@shad-claiborne/basic-oidc 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -33,11 +33,13 @@ export interface AuthorizationResponse {
33
33
  state?: string;
34
34
  }
35
35
  export interface TokenSet {
36
+ access_token?: string;
37
+ refresh_token?: string;
38
+ id_token?: string;
39
+ }
40
+ export interface TokenResponse extends TokenSet {
36
41
  token_type: string;
37
- access_token: string;
38
42
  expires_in: number;
39
- refresh_token: string;
40
- id_token?: string;
41
43
  }
42
44
  export interface Identity {
43
45
  sub: string;
@@ -218,9 +220,9 @@ export declare class IdentityProvider {
218
220
  * getIdentity
219
221
  * @param client Client
220
222
  * @param tokenSet TokenSet
221
- * @returns Promise<Identity | null>
223
+ * @returns Promise<Identity>
222
224
  */
223
- getIdentity(client: Client, tokenSet: TokenSet): Promise<Identity | null>;
225
+ getIdentity(client: Client, tokenSet: TokenSet): Promise<Identity>;
224
226
  }
225
227
  /**
226
228
  * class Client
@@ -260,9 +262,9 @@ export declare class Client {
260
262
  * requestAccess
261
263
  * @param authResponse AuthorizationResponse
262
264
  * @param codeVerifier string
263
- * @returns Promise<TokenSet>
265
+ * @returns Promise<TokenResponse>
264
266
  */
265
- requestAccess(authResponse: AuthorizationResponse, codeVerifier?: string): Promise<TokenSet>;
267
+ requestAccess(authResponse: AuthorizationResponse, codeVerifier?: string): Promise<TokenResponse>;
266
268
  /**
267
269
  * refreshAccess
268
270
  * @param tokenSet TokenSet
package/dist/index.js CHANGED
@@ -327,19 +327,21 @@ class IdentityProvider {
327
327
  * getIdentity
328
328
  * @param client Client
329
329
  * @param tokenSet TokenSet
330
- * @returns Promise<Identity | null>
330
+ * @returns Promise<Identity>
331
331
  */
332
332
  async getIdentity(client, tokenSet) {
333
- let id = null;
333
+ let id;
334
334
  if (tokenSet.id_token) {
335
335
  const jwks = (0, jose_1.createRemoteJWKSet)(new URL(this.config.jwks_uri));
336
336
  const { payload } = await (0, jose_1.jwtVerify)(tokenSet.id_token, jwks, { issuer: this.config.issuer });
337
337
  id = payload;
338
338
  }
339
- else {
339
+ else if (tokenSet.access_token) {
340
340
  const api = new IdentityProviderApi(this, tokenSet);
341
341
  id = await api.fetchUserinfo();
342
342
  }
343
+ else
344
+ throw new Error('invalid token set');
343
345
  return id;
344
346
  }
345
347
  }
@@ -430,7 +432,7 @@ class Client {
430
432
  * requestAccess
431
433
  * @param authResponse AuthorizationResponse
432
434
  * @param codeVerifier string
433
- * @returns Promise<TokenSet>
435
+ * @returns Promise<TokenResponse>
434
436
  */
435
437
  async requestAccess(authResponse, codeVerifier) {
436
438
  const tokenRequest = new TokenRequest(this);
@@ -449,6 +451,8 @@ class Client {
449
451
  * @returns Promise<TokenSet>
450
452
  */
451
453
  async refreshAccess(tokenSet) {
454
+ if (tokenSet.refresh_token === undefined)
455
+ throw new Error('undefined refresh token');
452
456
  const tokenRequest = new TokenRequest(this)
453
457
  .setRefreshToken(tokenSet.refresh_token)
454
458
  .setGrantType('refresh_token');
@@ -461,6 +465,8 @@ class Client {
461
465
  * @returns Promise<void>
462
466
  */
463
467
  async revokeAccess(tokenSet) {
468
+ if (tokenSet.access_token === undefined)
469
+ throw new Error('undefined access token');
464
470
  const params = new URLSearchParams();
465
471
  params.append('client_id', this.clientId);
466
472
  params.append('client_secret', this.clientSecret);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shad-claiborne/basic-oidc",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Basic OpenID Connect library",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",