Skip to content

Commit

Permalink
feat: add organisation resource id (#58)
Browse files Browse the repository at this point in the history
- the organisation resource id will be added to the scope. Users will be
created in the specific organisation while the registration

---------

Co-authored-by: Alexander Classen <[email protected]>
  • Loading branch information
Clex1o1 and Alexander Classen authored Aug 13, 2024
1 parent b5ca273 commit a6cba96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const zitadelAuth = createZITADELAuth({
issuer: `${myZITADELInstancesOrigin}`,
client_id: `${myApplicationsClientID}`,
project_resource_id: `${myApplicationsProjectResourceID}`,
organization_id: `${myApplicationsOrganizationID}`, // optional
})
```

Expand All @@ -55,6 +56,9 @@ The following defaults apply:
- If you specify a *project_resource_id*, the scopes for retrieving the users roles from the user info endpoint are added automatically.
You can conveniently use `zitadelAuth.hasRole("someRoleKey")`.

Optional:
- add an *organization_id* to register and login users directly in the organization scope.

## Running the Example

### Recommended IDE Setup
Expand Down
6 changes: 5 additions & 1 deletion lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const zitadelAuth = createZITADELAuth({
issuer: `${myZITADELInstancesOrigin}`,
client_id: `${myApplicationsClientID}`,
project_resource_id: `${myApplicationsProjectResourceID}`,
organization_id: `${myApplicationsOrganizationID}`, // optional
})
```

Expand All @@ -36,4 +37,7 @@ The following defaults apply:
- ZITADELs user info endpoint is called to enrich the user profile.
- The access token is refreshed automatically by default before it expires.
- If you specify a *project_resource_id*, the scopes for retrieving the users roles from the user info endpoint are added automatically.
You can conveniently use `zitadelAuth.hasRole("someRoleKey")`.
You can conveniently use `zitadelAuth.hasRole("someRoleKey")`.

Optional:
- add an organization_id to register and login users directly in the organization scope.
4 changes: 3 additions & 1 deletion lib/src/zitadelAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ZITADELConfig {
client_id: string
issuer: string
project_resource_id?: string
org_id?: string
}

export function createZITADELAuth(
Expand All @@ -23,7 +24,8 @@ export function createZITADELAuth(
(zitadelConfig.project_resource_id ?
` urn:zitadel:iam:org:project:id:${zitadelConfig.project_resource_id}:aud` +
' urn:zitadel:iam:org:projects:roles'
: ''),
: '')
+ (zitadelConfig.org_id ? ` urn:zitadel:iam:org:id:${zitadelConfig.org_id}` : ''),
authority: zitadelConfig.issuer,
client_id: zitadelConfig.client_id,
loadUserInfo: true,
Expand Down

0 comments on commit a6cba96

Please sign in to comment.