-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8de426d
commit 3399c11
Showing
6 changed files
with
136 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,38 @@ | ||
import { SetMetadata } from '@nestjs/common'; | ||
import * as KeycloakConnect from 'keycloak-connect'; | ||
|
||
export const META_SCOPES = 'scopes'; | ||
|
||
export const META_CONDITIONAL_SCOPES = 'conditional-scopes'; | ||
|
||
export type ConditionalScopeFn = ( | ||
request: any, | ||
token: KeycloakConnect.Token, | ||
) => string[]; | ||
|
||
/** | ||
* Keycloak Authorization Scopes. | ||
* Keycloak authorization scopes. | ||
* @param scopes - scopes that are associated with the resource | ||
*/ | ||
export const Scopes = (...scopes: string[]) => SetMetadata(META_SCOPES, scopes); | ||
|
||
/** | ||
* Keycloak authorization conditional scopes. | ||
* @param scopes - scopes that are associated with the resource depending on the conditions | ||
*/ | ||
export const ConditionalScopes = (resolver: ConditionalScopeFn) => | ||
SetMetadata(META_CONDITIONAL_SCOPES, resolver); | ||
|
||
import { createParamDecorator, ExecutionContext } from '@nestjs/common'; | ||
import { extractRequest } from '../util'; | ||
|
||
/** | ||
* Retrieves the resolved scopes. | ||
* @since 1.5.0 | ||
*/ | ||
export const ResolvedScopes = createParamDecorator( | ||
(data: unknown, ctx: ExecutionContext) => { | ||
const [req] = extractRequest(ctx); | ||
return req.scopes; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters