diff --git a/lib/apis/ConnectedAppsApi.ts b/lib/apis/ConnectedAppsApi.ts index 7c3a643..acda76e 100644 --- a/lib/apis/ConnectedAppsApi.ts +++ b/lib/apis/ConnectedAppsApi.ts @@ -33,7 +33,8 @@ import { export interface GetConnectedAppAuthUrlRequest { keyCodeRef: string; - userId: string; + userId?: string; + orgCode?: string; } export interface GetConnectedAppTokenRequest { @@ -58,10 +59,6 @@ export class ConnectedAppsApi extends runtime.BaseAPI { throw new runtime.RequiredError('keyCodeRef','Required parameter requestParameters.keyCodeRef was null or undefined when calling getConnectedAppAuthUrl.'); } - if (requestParameters.userId === null || requestParameters.userId === undefined) { - throw new runtime.RequiredError('userId','Required parameter requestParameters.userId was null or undefined when calling getConnectedAppAuthUrl.'); - } - const queryParameters: any = {}; if (requestParameters.keyCodeRef !== undefined) { @@ -72,6 +69,10 @@ export class ConnectedAppsApi extends runtime.BaseAPI { queryParameters['user_id'] = requestParameters.userId; } + if (requestParameters.orgCode !== undefined) { + queryParameters['org_code'] = requestParameters.orgCode; + } + const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { diff --git a/lib/sdk/utilities/token-utils.ts b/lib/sdk/utilities/token-utils.ts index f174ced..c38074c 100644 --- a/lib/sdk/utilities/token-utils.ts +++ b/lib/sdk/utilities/token-utils.ts @@ -1,19 +1,7 @@ +import { type JwtPayload, jwtDecode } from 'jwt-decode'; import type { TokenCollection, UserType, TokenType } from './types.js'; import { type SessionManager } from '../session-managers/index.js'; -/** - * Parses a provided JWT token to extract the payload segment of said - * token. - * @param token {string} - * @returns {any} - */ -const getTokenPayload = (token: string): any => { - try { - return JSON.parse(atob(token.split('.')[1])); - } catch (e) { - return null; - } -}; /** * Extracts the payload from the provided idToken and saves the extracted @@ -26,13 +14,13 @@ const commitUserToMemoryFromToken = async ( sessionManager: SessionManager, idToken: string ): Promise => { - const idTokenPayload = getTokenPayload(idToken); + const idTokenPayload = jwtDecode(idToken); const user: UserType = { family_name: idTokenPayload.family_name, given_name: idTokenPayload.given_name, picture: idTokenPayload.picture ?? null, email: idTokenPayload.email, - id: idTokenPayload.sub, + id: idTokenPayload.sub!, }; await sessionManager.setSessionItem('user', user); @@ -49,7 +37,7 @@ export const commitTokenToMemory = async ( token: string, type: TokenType ): Promise => { - const tokenPayload = getTokenPayload(token); + const tokenPayload = jwtDecode(token); await sessionManager.setSessionItem(type, token); if (type === 'access_token') { await sessionManager.setSessionItem('access_token_payload', tokenPayload); @@ -138,6 +126,6 @@ export const commitUserToMemory = async ( export const isTokenExpired = (token: string | null): boolean => { if (!token) return true; const currentUnixTime = Math.floor(Date.now() / 1000); - const tokenPayload = getTokenPayload(token); - return currentUnixTime >= tokenPayload.exp; + const tokenPayload = jwtDecode(token); + return currentUnixTime >= tokenPayload.exp!; }; diff --git a/package.json b/package.json index f6e5829..23925c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kinde-oss/kinde-typescript-sdk", - "version": "2.2.3", + "version": "2.2.4", "description": "Kinde Typescript SDK", "main": "dist-cjs/index.js", "module": "dist/index.js", @@ -15,7 +15,7 @@ "types": "./dist-cjs/types/index.d.ts", "default": "./dist-cjs/index.js" }, - "import":{ + "import": { "types": "./dist/types/index.d.ts", "default": "./dist/index.js" } @@ -70,6 +70,7 @@ "typescript": "^5.0.4" }, "dependencies": { + "jwt-decode": "^4.0.0", "uncrypto": "^0.1.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6dba7a4..0225b20 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + jwt-decode: + specifier: ^4.0.0 + version: 4.0.0 uncrypto: specifier: ^0.1.3 version: 0.1.3 @@ -3288,6 +3291,11 @@ packages: hasBin: true dev: true + /jwt-decode@4.0.0: + resolution: {integrity: sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==} + engines: {node: '>=18'} + dev: false + /kleur@3.0.3: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'}