|
5 | 5 | IntrospectionRequest, |
6 | 6 | IntrospectionResponse, |
7 | 7 | PasswordRequest, |
| 8 | + JwtBearerRequest, |
8 | 9 | OAuth2TokenTypeHint, |
9 | 10 | RefreshRequest, |
10 | 11 | RevocationRequest, |
@@ -42,6 +43,15 @@ type PasswordParams = { |
42 | 43 |
|
43 | 44 | } |
44 | 45 |
|
| 46 | +type JwtBearerParams = { |
| 47 | + /** |
| 48 | + * The JSON Web Token to use for the JWT Bearer token request. |
| 49 | + */ |
| 50 | + assertion: string; |
| 51 | + |
| 52 | + scope?: string[]; |
| 53 | +} |
| 54 | + |
45 | 55 | /** |
46 | 56 | * Extra options that may be passed to refresh() |
47 | 57 | */ |
@@ -79,8 +89,8 @@ export interface ClientSettings { |
79 | 89 | * OAuth2 clientSecret |
80 | 90 | * |
81 | 91 | * This is required when using the 'client_secret_basic' authenticationMethod |
82 | | - * for the client_credentials and password flows, but not authorization_code |
83 | | - * or implicit. |
| 92 | + * for the client_credentials and password flows, but not authorization_code, |
| 93 | + * implicit or JWT Bearer. |
84 | 94 | */ |
85 | 95 | clientSecret?: string; |
86 | 96 |
|
@@ -225,6 +235,19 @@ export class OAuth2Client { |
225 | 235 |
|
226 | 236 | } |
227 | 237 |
|
| 238 | + /** |
| 239 | + * Retrieves an OAuth2 token using the 'urn:ietf:params:oauth:grant-type:jwt-bearer' grant. |
| 240 | + */ |
| 241 | + async jwtBearer(params: JwtBearerParams): Promise<OAuth2Token> { |
| 242 | + |
| 243 | + const body: JwtBearerRequest = { |
| 244 | + grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer', |
| 245 | + assertion: params.assertion, |
| 246 | + scope: params.scope?.join(' '), |
| 247 | + }; |
| 248 | + return this.tokenResponseToOAuth2Token(this.request('tokenEndpoint', body)); |
| 249 | + } |
| 250 | + |
228 | 251 | /** |
229 | 252 | * Returns the helper object for the `authorization_code` grant. |
230 | 253 | */ |
@@ -366,7 +389,7 @@ export class OAuth2Client { |
366 | 389 | /** |
367 | 390 | * Does a HTTP request on the 'token' endpoint. |
368 | 391 | */ |
369 | | - async request(endpoint: 'tokenEndpoint', body: RefreshRequest | ClientCredentialsRequest | PasswordRequest | AuthorizationCodeRequest): Promise<TokenResponse>; |
| 392 | + async request(endpoint: 'tokenEndpoint', body: RefreshRequest | ClientCredentialsRequest | PasswordRequest | JwtBearerRequest | AuthorizationCodeRequest): Promise<TokenResponse>; |
370 | 393 | async request(endpoint: 'introspectionEndpoint', body: IntrospectionRequest): Promise<IntrospectionResponse>; |
371 | 394 | async request(endpoint: 'revocationEndpoint', body: RevocationRequest): Promise<void>; |
372 | 395 | async request(endpoint: OAuth2Endpoint, body: Record<string, any>): Promise<unknown> { |
|
0 commit comments