@asgardeo/express 0.0.48 → 0.0.50

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/__legacy__/client.ts", "../../src/__legacy__/constants/default-options.ts", "../../src/__legacy__/middleware/protect-route.ts", "../../src/__legacy__/middleware/authentication.ts", "../../src/__legacy__/utils/express-utils.ts"],
4
- "sourcesContent": ["/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport * from \"./__legacy__/models\";\nexport * from \"./__legacy__/client\";\n\nexport * from '@asgardeo/node';\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport {\n LegacyAsgardeoNodeClient,\n AuthClientConfig,\n AuthURLCallback,\n TokenResponse,\n Storage,\n User,\n OIDCEndpoints,\n IdToken,\n TokenExchangeRequestConfig,\n AsgardeoAuthException,\n Logger,\n} from '@asgardeo/node';\nimport {CookieConfig, DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH} from './constants';\nimport {ExpressClientConfig, UnauthenticatedCallback} from './models';\nimport express from 'express';\nimport {v4 as uuidv4} from 'uuid';\nimport {asgardeoExpressAuth, protectRoute} from './middleware';\nimport {ExpressUtils} from './utils/express-utils';\n\nexport class AsgardeoExpressClient {\n private _authClient: LegacyAsgardeoNodeClient<AuthClientConfig>;\n private _storage?: Storage;\n private static _clientConfig: ExpressClientConfig;\n\n private static _instance: AsgardeoExpressClient;\n\n private constructor(config: ExpressClientConfig, storage?: Storage) {\n //Set the client config\n AsgardeoExpressClient._clientConfig = {...config};\n\n //Add the afterSignInUrl and afterSignOutUrl\n //Add custom paths if the user has already declared any or else use the defaults\n const nodeClientConfig: AuthClientConfig = {\n ...config,\n afterSignInUrl: config.appURL + (config.loginPath || DEFAULT_LOGIN_PATH),\n afterSignOutUrl: config.appURL + (config.logoutPath || DEFAULT_LOGOUT_PATH),\n };\n\n //Initialize the user provided storage if there is any\n if (storage) {\n Logger.debug('Initializing user provided storage');\n this._storage = storage;\n }\n\n //Initialize the Auth Client\n this._authClient = new LegacyAsgardeoNodeClient();\n this._authClient.initialize(nodeClientConfig, this._storage);\n }\n\n public static getInstance(config: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient;\n public static getInstance(): AsgardeoExpressClient;\n public static getInstance(config?: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient {\n //Create a new instance if its not instantiated already\n if (!AsgardeoExpressClient._instance && config) {\n AsgardeoExpressClient._instance = new AsgardeoExpressClient(config, storage);\n Logger.debug('Initialized AsgardeoExpressClient successfully');\n }\n\n if (!AsgardeoExpressClient._instance && !config) {\n throw Error(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-GI1-NF01',\n 'User configuration is not found',\n 'User config has not been passed to initialize AsgardeoExpressClient',\n ).toString(),\n );\n }\n\n return AsgardeoExpressClient._instance;\n }\n\n public async signIn(\n req: express.Request,\n res: express.Response,\n next: express.nextFunction,\n signInConfig?: Record<string, string | boolean>,\n ): Promise<TokenResponse> {\n if (ExpressUtils.hasErrorInURL(req.originalUrl)) {\n return Promise.reject(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-SI-IV01',\n 'Invalid login request URL',\n 'Login request contains an error query parameter in the URL',\n ),\n );\n }\n\n //Check if the user has a valid user ID and if not create one\n let userId = req.cookies.ASGARDEO_SESSION_ID;\n if (!userId) {\n userId = uuidv4();\n }\n\n //Handle signIn() callback\n const authRedirectCallback = (url: string) => {\n if (url) {\n //DEBUG\n Logger.debug('Redirecting to: ' + url);\n res.cookie('ASGARDEO_SESSION_ID', userId, {\n maxAge: AsgardeoExpressClient._clientConfig.cookieConfig?.maxAge\n ? AsgardeoExpressClient._clientConfig.cookieConfig.maxAge\n : CookieConfig.defaultMaxAge,\n httpOnly: AsgardeoExpressClient._clientConfig.cookieConfig?.httpOnly ?? CookieConfig.defaultHttpOnly,\n sameSite: AsgardeoExpressClient._clientConfig.cookieConfig?.sameSite ?? CookieConfig.defaultSameSite,\n secure: AsgardeoExpressClient._clientConfig.cookieConfig?.secure ?? CookieConfig.defaultSecure,\n });\n res.redirect(url);\n\n next && typeof next === 'function' && next();\n }\n };\n\n const authResponse: TokenResponse = await this._authClient.signIn(\n authRedirectCallback,\n userId,\n req.query.code,\n req.query.session_state,\n req.query.state,\n signInConfig,\n );\n\n if (authResponse.accessToken || authResponse.idToken) {\n return authResponse;\n } else {\n return {\n accessToken: '',\n createdAt: 0,\n expiresIn: '',\n idToken: '',\n refreshToken: '',\n scope: '',\n tokenType: '',\n };\n }\n }\n\n public async signOut(userId: string): Promise<string> {\n return this._authClient.signOut(userId);\n }\n\n public async isSignedIn(userId: string): Promise<boolean> {\n return this._authClient.isSignedIn(userId);\n }\n\n public async getIdToken(userId: string): Promise<string> {\n return this._authClient.getIdToken(userId);\n }\n\n public async getUser(userId: string): Promise<User> {\n return this._authClient.getUser(userId);\n }\n\n public async getOpenIDProviderEndpoints(): Promise<OIDCEndpoints> {\n return this._authClient.getOpenIDProviderEndpoints();\n }\n\n public async getDecodedIdToken(userId?: string): Promise<IdToken> {\n return this._authClient.getDecodedIdToken(userId);\n }\n\n public async getAccessToken(userId?: string): Promise<string> {\n return this._authClient.getAccessToken(userId);\n }\n\n public async exchangeToken(config: TokenExchangeRequestConfig, userId?: string): Promise<TokenResponse | Response> {\n return this._authClient.exchangeToken(config, userId);\n }\n\n public async reInitialize(config: Partial<AuthClientConfig>): Promise<void> {\n return this._authClient.reInitialize(config);\n }\n\n public async revokeAccessToken(userId?: string): Promise<Response> {\n return this._authClient.revokeAccessToken(userId);\n }\n\n public static didSignOutFail(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.didSignOutFail(afterSignOutUrl);\n }\n\n public static isSignOutSuccessful(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);\n }\n\n public static protectRoute(\n callback: UnauthenticatedCallback,\n ): (req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void> {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-PR-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return protectRoute(this._instance, callback);\n }\n\n public static asgardeoExpressAuth(\n onSignIn: (response: TokenResponse) => void,\n onSignOut: () => void,\n onError: (exception: AsgardeoAuthException) => void,\n ): any {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-AEA-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return asgardeoExpressAuth(this._instance, AsgardeoExpressClient._clientConfig, onSignIn, onSignOut, onError);\n }\n\n public async getStorageManager() {\n return this._authClient.getStorageManager();\n }\n}\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport enum CookieConfig {\n defaultMaxAge = 90000,\n defaultHttpOnly = 'true',\n defaultSameSite = 'lax',\n defaultSecure = 'false'\n}\n\nexport const DEFAULT_LOGIN_PATH = \"/login\";\n\nexport const DEFAULT_LOGOUT_PATH = \"/logout\";\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport express from 'express';\nimport {AsgardeoExpressClient} from '../client';\nimport {UnauthenticatedCallback} from '../models';\nimport {Logger} from '@asgardeo/node';\n\nexport const protectRoute = (\n asgardeoExpressClient: AsgardeoExpressClient,\n callback: UnauthenticatedCallback,\n): ((req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void>) => {\n return async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n Logger.error('No session ID found in the request cookies');\n\n if (callback(res, 'Unauthenticated')) {\n return;\n }\n\n return next();\n } else {\n //validate the cookie\n const isCookieValid = await asgardeoExpressClient.isSignedIn(req.cookies.ASGARDEO_SESSION_ID);\n if (isCookieValid) {\n return next();\n } else {\n Logger.error('Invalid session ID found in the request cookies');\n if (callback(res, 'Invalid session cookie')) {\n return;\n }\n\n return next();\n }\n }\n };\n};\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport { AsgardeoAuthException, Storage, TokenResponse, Logger } from \"@asgardeo/node\";\nimport express from \"express\";\nimport { AsgardeoExpressClient } from \"../client\";\nimport { DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH } from \"../constants\";\nimport { ExpressClientConfig } from \"../models\";\n\nexport const asgardeoExpressAuth = (\n asgardeoExpressClient: AsgardeoExpressClient,\n config: ExpressClientConfig,\n onSignIn: (res: express.Response, tokenResponse: TokenResponse) => void,\n onSignOut: (res: express.Response) => void,\n onError: (res: express.Response, exception: AsgardeoAuthException) => void\n): any => {\n //Create the router\n const router = new express.Router();\n\n //Patch AuthClient to the request and the response\n router.use(async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n req.asgardeoAuth = asgardeoExpressClient;\n res.asgardeoAuth = asgardeoExpressClient;\n next();\n });\n\n //Patch in '/login' route\n router.get(\n config.loginPath || DEFAULT_LOGIN_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n try {\n const response: TokenResponse = await asgardeoExpressClient.signIn(req, res, next, config.signInConfig);\n if (response.accessToken || response.idToken) {\n onSignIn(res, response);\n }\n } catch (e: any) {\n Logger.error(e.message);\n onError(res, e);\n }\n }\n );\n\n //Patch in '/logout' route\n router.get(\n config.logoutPath || DEFAULT_LOGOUT_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n //Check if it is a logout success response\n if (req.query.state === \"sign_out_success\") {\n onSignOut(res);\n\n return;\n }\n\n //Check if the cookie exists\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n onError(\n res,\n new AsgardeoAuthException(\n \"EXPRESS-AUTH_MW-LOGOUT-NF01\",\n \"No cookie found in the request\",\n \"No cookie was sent with the request. The user may not have signed in yet.\"\n )\n );\n\n return;\n } else {\n //Get the signout URL\n try {\n const signOutURL = await req.asgardeoAuth.signOut(req.cookies.ASGARDEO_SESSION_ID);\n if (signOutURL) {\n res.cookie(\"ASGARDEO_SESSION_ID\", null, { maxAge: 0 });\n res.redirect(signOutURL);\n\n return;\n }\n } catch (e: any) {\n onError(res, e);\n\n return;\n }\n }\n }\n );\n\n return router;\n};\n", "export class ExpressUtils {\n\n private static readonly AUTH_CODE_REGEXP: RegExp = /[?&]error=[^&]+/;\n\n /**\n * Util function to check if the URL contains an error.\n *\n * @param url - URL to be checked.\n *\n * @returns {boolean} - True if the URL contains an error.\n */\n public static hasErrorInURL(url: string): boolean {\n\n return this.AUTH_CODE_REGEXP.test(url);\n }\n}\n"],
4
+ "sourcesContent": ["/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport * from './__legacy__/models';\nexport * from './__legacy__/client';\n\nexport * from '@asgardeo/node';\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport {\n LegacyAsgardeoNodeClient,\n AuthClientConfig,\n AuthURLCallback,\n TokenResponse,\n Storage,\n User,\n OIDCEndpoints,\n IdToken,\n TokenExchangeRequestConfig,\n AsgardeoAuthException,\n Logger,\n} from '@asgardeo/node';\nimport {CookieConfig, DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH} from './constants';\nimport {ExpressClientConfig, UnauthenticatedCallback} from './models';\nimport express from 'express';\nimport {v4 as uuidv4} from 'uuid';\nimport {asgardeoExpressAuth, protectRoute} from './middleware';\nimport {ExpressUtils} from './utils/express-utils';\n\nexport class AsgardeoExpressClient {\n private _authClient: LegacyAsgardeoNodeClient<AuthClientConfig>;\n private _storage?: Storage;\n private static _clientConfig: ExpressClientConfig;\n\n private static _instance: AsgardeoExpressClient;\n\n private constructor(config: ExpressClientConfig, storage?: Storage) {\n //Set the client config\n AsgardeoExpressClient._clientConfig = {...config};\n\n //Add the afterSignInUrl and afterSignOutUrl\n //Add custom paths if the user has already declared any or else use the defaults\n const nodeClientConfig: AuthClientConfig = {\n ...config,\n afterSignInUrl: config.appURL + (config.loginPath || DEFAULT_LOGIN_PATH),\n afterSignOutUrl: config.appURL + (config.logoutPath || DEFAULT_LOGOUT_PATH),\n };\n\n //Initialize the user provided storage if there is any\n if (storage) {\n Logger.debug('Initializing user provided storage');\n this._storage = storage;\n }\n\n //Initialize the Auth Client\n this._authClient = new LegacyAsgardeoNodeClient();\n this._authClient.initialize(nodeClientConfig, this._storage);\n }\n\n public static getInstance(config: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient;\n public static getInstance(): AsgardeoExpressClient;\n public static getInstance(config?: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient {\n //Create a new instance if its not instantiated already\n if (!AsgardeoExpressClient._instance && config) {\n AsgardeoExpressClient._instance = new AsgardeoExpressClient(config, storage);\n Logger.debug('Initialized AsgardeoExpressClient successfully');\n }\n\n if (!AsgardeoExpressClient._instance && !config) {\n throw Error(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-GI1-NF01',\n 'User configuration is not found',\n 'User config has not been passed to initialize AsgardeoExpressClient',\n ).toString(),\n );\n }\n\n return AsgardeoExpressClient._instance;\n }\n\n public async signIn(\n req: express.Request,\n res: express.Response,\n next: express.nextFunction,\n signInConfig?: Record<string, string | boolean>,\n ): Promise<TokenResponse> {\n if (ExpressUtils.hasErrorInURL(req.originalUrl)) {\n return Promise.reject(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-SI-IV01',\n 'Invalid login request URL',\n 'Login request contains an error query parameter in the URL',\n ),\n );\n }\n\n //Check if the user has a valid user ID and if not create one\n let userId = req.cookies.ASGARDEO_SESSION_ID;\n if (!userId) {\n userId = uuidv4();\n }\n\n //Handle signIn() callback\n const authRedirectCallback = (url: string) => {\n if (url) {\n //DEBUG\n Logger.debug('Redirecting to: ' + url);\n res.cookie('ASGARDEO_SESSION_ID', userId, {\n maxAge: AsgardeoExpressClient._clientConfig.cookieConfig?.maxAge\n ? AsgardeoExpressClient._clientConfig.cookieConfig.maxAge\n : CookieConfig.defaultMaxAge,\n httpOnly: AsgardeoExpressClient._clientConfig.cookieConfig?.httpOnly ?? CookieConfig.defaultHttpOnly,\n sameSite: AsgardeoExpressClient._clientConfig.cookieConfig?.sameSite ?? CookieConfig.defaultSameSite,\n secure: AsgardeoExpressClient._clientConfig.cookieConfig?.secure ?? CookieConfig.defaultSecure,\n });\n res.redirect(url);\n\n next && typeof next === 'function' && next();\n }\n };\n\n const authResponse: TokenResponse = await this._authClient.signIn(\n authRedirectCallback,\n userId,\n req.query.code,\n req.query.session_state,\n req.query.state,\n signInConfig,\n );\n\n if (authResponse.accessToken || authResponse.idToken) {\n return authResponse;\n } else {\n return {\n accessToken: '',\n createdAt: 0,\n expiresIn: '',\n idToken: '',\n refreshToken: '',\n scope: '',\n tokenType: '',\n };\n }\n }\n\n public async signOut(userId: string): Promise<string> {\n return this._authClient.signOut(userId);\n }\n\n public async isSignedIn(userId: string): Promise<boolean> {\n return this._authClient.isSignedIn(userId);\n }\n\n public async getIdToken(userId: string): Promise<string> {\n return this._authClient.getIdToken(userId);\n }\n\n public async getUser(userId: string): Promise<User> {\n return this._authClient.getUser(userId);\n }\n\n public async getOpenIDProviderEndpoints(): Promise<OIDCEndpoints> {\n return this._authClient.getOpenIDProviderEndpoints();\n }\n\n public async getDecodedIdToken(userId?: string): Promise<IdToken> {\n return this._authClient.getDecodedIdToken(userId);\n }\n\n public async getAccessToken(userId?: string): Promise<string> {\n return this._authClient.getAccessToken(userId);\n }\n\n public async exchangeToken(config: TokenExchangeRequestConfig, userId?: string): Promise<TokenResponse | Response> {\n return this._authClient.exchangeToken(config, userId);\n }\n\n public async reInitialize(config: Partial<AuthClientConfig>): Promise<void> {\n return this._authClient.reInitialize(config);\n }\n\n public async revokeAccessToken(userId?: string): Promise<Response> {\n return this._authClient.revokeAccessToken(userId);\n }\n\n public static didSignOutFail(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.didSignOutFail(afterSignOutUrl);\n }\n\n public static isSignOutSuccessful(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);\n }\n\n public static protectRoute(\n callback: UnauthenticatedCallback,\n ): (req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void> {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-PR-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return protectRoute(this._instance, callback);\n }\n\n public static asgardeoExpressAuth(\n onSignIn: (response: TokenResponse) => void,\n onSignOut: () => void,\n onError: (exception: AsgardeoAuthException) => void,\n ): any {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-AEA-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return asgardeoExpressAuth(this._instance, AsgardeoExpressClient._clientConfig, onSignIn, onSignOut, onError);\n }\n\n public async getStorageManager() {\n return this._authClient.getStorageManager();\n }\n}\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport enum CookieConfig {\n defaultMaxAge = 90000,\n defaultHttpOnly = 'true',\n defaultSameSite = 'lax',\n defaultSecure = 'false'\n}\n\nexport const DEFAULT_LOGIN_PATH = \"/login\";\n\nexport const DEFAULT_LOGOUT_PATH = \"/logout\";\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport express from 'express';\nimport {AsgardeoExpressClient} from '../client';\nimport {UnauthenticatedCallback} from '../models';\nimport {Logger} from '@asgardeo/node';\n\nexport const protectRoute = (\n asgardeoExpressClient: AsgardeoExpressClient,\n callback: UnauthenticatedCallback,\n): ((req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void>) => {\n return async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n Logger.error('No session ID found in the request cookies');\n\n if (callback(res, 'Unauthenticated')) {\n return;\n }\n\n return next();\n } else {\n //validate the cookie\n const isCookieValid = await asgardeoExpressClient.isSignedIn(req.cookies.ASGARDEO_SESSION_ID);\n if (isCookieValid) {\n return next();\n } else {\n Logger.error('Invalid session ID found in the request cookies');\n if (callback(res, 'Invalid session cookie')) {\n return;\n }\n\n return next();\n }\n }\n };\n};\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport { AsgardeoAuthException, Storage, TokenResponse, Logger } from \"@asgardeo/node\";\nimport express from \"express\";\nimport { AsgardeoExpressClient } from \"../client\";\nimport { DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH } from \"../constants\";\nimport { ExpressClientConfig } from \"../models\";\n\nexport const asgardeoExpressAuth = (\n asgardeoExpressClient: AsgardeoExpressClient,\n config: ExpressClientConfig,\n onSignIn: (res: express.Response, tokenResponse: TokenResponse) => void,\n onSignOut: (res: express.Response) => void,\n onError: (res: express.Response, exception: AsgardeoAuthException) => void\n): any => {\n //Create the router\n const router = new express.Router();\n\n //Patch AuthClient to the request and the response\n router.use(async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n req.asgardeoAuth = asgardeoExpressClient;\n res.asgardeoAuth = asgardeoExpressClient;\n next();\n });\n\n //Patch in '/login' route\n router.get(\n config.loginPath || DEFAULT_LOGIN_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n try {\n const response: TokenResponse = await asgardeoExpressClient.signIn(req, res, next, config.signInConfig);\n if (response.accessToken || response.idToken) {\n onSignIn(res, response);\n }\n } catch (e: any) {\n Logger.error(e.message);\n onError(res, e);\n }\n }\n );\n\n //Patch in '/logout' route\n router.get(\n config.logoutPath || DEFAULT_LOGOUT_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n //Check if it is a logout success response\n if (req.query.state === \"sign_out_success\") {\n onSignOut(res);\n\n return;\n }\n\n //Check if the cookie exists\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n onError(\n res,\n new AsgardeoAuthException(\n \"EXPRESS-AUTH_MW-LOGOUT-NF01\",\n \"No cookie found in the request\",\n \"No cookie was sent with the request. The user may not have signed in yet.\"\n )\n );\n\n return;\n } else {\n //Get the signout URL\n try {\n const signOutURL = await req.asgardeoAuth.signOut(req.cookies.ASGARDEO_SESSION_ID);\n if (signOutURL) {\n res.cookie(\"ASGARDEO_SESSION_ID\", null, { maxAge: 0 });\n res.redirect(signOutURL);\n\n return;\n }\n } catch (e: any) {\n onError(res, e);\n\n return;\n }\n }\n }\n );\n\n return router;\n};\n", "export class ExpressUtils {\n\n private static readonly AUTH_CODE_REGEXP: RegExp = /[?&]error=[^&]+/;\n\n /**\n * Util function to check if the URL contains an error.\n *\n * @param url - URL to be checked.\n *\n * @returns {boolean} - True if the URL contains an error.\n */\n public static hasErrorInURL(url: string): boolean {\n\n return this.AUTH_CODE_REGEXP.test(url);\n }\n}\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACk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AM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,aAAa,KAAK,WAAW,QAAQ;AAAA,EAC9C;AAAA,EAEA,OAAc,oBACZ,UACA,WACA,SACK;AACL,QAAI,CAAC,KAAK,WAAW;AACnB,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAoB,KAAK,WAAW,uBAAsB,eAAe,UAAU,WAAW,OAAO;AAAA,EAC9G;AAAA,EAEA,MAAa,oBAAoB;AAC/B,WAAO,KAAK,YAAY,kBAAkB;AAAA,EAC5C;AACF;AAnME,cAHW,wBAGI;AAEf,cALW,wBAKI;AALV,IAAM,wBAAN;;;ADjBP,0BAAc,2BArBd;",
6
6
  "names": ["import_node", "import_node", "express", "uuidv4"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
3
  *
4
- * WSO2 Inc. licenses this file to you under the Apache License,
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
5
  * Version 2.0 (the "License"); you may not use this file except
6
6
  * in compliance with the License.
7
7
  * You may obtain a copy of the License at
@@ -15,6 +15,6 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- export * from "./__legacy__/models";
19
- export * from "./__legacy__/client";
18
+ export * from './__legacy__/models';
19
+ export * from './__legacy__/client';
20
20
  export * from '@asgardeo/node';
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/__legacy__/client.ts", "../src/__legacy__/constants/default-options.ts", "../src/__legacy__/middleware/protect-route.ts", "../src/__legacy__/middleware/authentication.ts", "../src/__legacy__/utils/express-utils.ts", "../src/index.ts"],
4
- "sourcesContent": ["/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport {\n LegacyAsgardeoNodeClient,\n AuthClientConfig,\n AuthURLCallback,\n TokenResponse,\n Storage,\n User,\n OIDCEndpoints,\n IdToken,\n TokenExchangeRequestConfig,\n AsgardeoAuthException,\n Logger,\n} from '@asgardeo/node';\nimport {CookieConfig, DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH} from './constants';\nimport {ExpressClientConfig, UnauthenticatedCallback} from './models';\nimport express from 'express';\nimport {v4 as uuidv4} from 'uuid';\nimport {asgardeoExpressAuth, protectRoute} from './middleware';\nimport {ExpressUtils} from './utils/express-utils';\n\nexport class AsgardeoExpressClient {\n private _authClient: LegacyAsgardeoNodeClient<AuthClientConfig>;\n private _storage?: Storage;\n private static _clientConfig: ExpressClientConfig;\n\n private static _instance: AsgardeoExpressClient;\n\n private constructor(config: ExpressClientConfig, storage?: Storage) {\n //Set the client config\n AsgardeoExpressClient._clientConfig = {...config};\n\n //Add the afterSignInUrl and afterSignOutUrl\n //Add custom paths if the user has already declared any or else use the defaults\n const nodeClientConfig: AuthClientConfig = {\n ...config,\n afterSignInUrl: config.appURL + (config.loginPath || DEFAULT_LOGIN_PATH),\n afterSignOutUrl: config.appURL + (config.logoutPath || DEFAULT_LOGOUT_PATH),\n };\n\n //Initialize the user provided storage if there is any\n if (storage) {\n Logger.debug('Initializing user provided storage');\n this._storage = storage;\n }\n\n //Initialize the Auth Client\n this._authClient = new LegacyAsgardeoNodeClient();\n this._authClient.initialize(nodeClientConfig, this._storage);\n }\n\n public static getInstance(config: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient;\n public static getInstance(): AsgardeoExpressClient;\n public static getInstance(config?: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient {\n //Create a new instance if its not instantiated already\n if (!AsgardeoExpressClient._instance && config) {\n AsgardeoExpressClient._instance = new AsgardeoExpressClient(config, storage);\n Logger.debug('Initialized AsgardeoExpressClient successfully');\n }\n\n if (!AsgardeoExpressClient._instance && !config) {\n throw Error(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-GI1-NF01',\n 'User configuration is not found',\n 'User config has not been passed to initialize AsgardeoExpressClient',\n ).toString(),\n );\n }\n\n return AsgardeoExpressClient._instance;\n }\n\n public async signIn(\n req: express.Request,\n res: express.Response,\n next: express.nextFunction,\n signInConfig?: Record<string, string | boolean>,\n ): Promise<TokenResponse> {\n if (ExpressUtils.hasErrorInURL(req.originalUrl)) {\n return Promise.reject(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-SI-IV01',\n 'Invalid login request URL',\n 'Login request contains an error query parameter in the URL',\n ),\n );\n }\n\n //Check if the user has a valid user ID and if not create one\n let userId = req.cookies.ASGARDEO_SESSION_ID;\n if (!userId) {\n userId = uuidv4();\n }\n\n //Handle signIn() callback\n const authRedirectCallback = (url: string) => {\n if (url) {\n //DEBUG\n Logger.debug('Redirecting to: ' + url);\n res.cookie('ASGARDEO_SESSION_ID', userId, {\n maxAge: AsgardeoExpressClient._clientConfig.cookieConfig?.maxAge\n ? AsgardeoExpressClient._clientConfig.cookieConfig.maxAge\n : CookieConfig.defaultMaxAge,\n httpOnly: AsgardeoExpressClient._clientConfig.cookieConfig?.httpOnly ?? CookieConfig.defaultHttpOnly,\n sameSite: AsgardeoExpressClient._clientConfig.cookieConfig?.sameSite ?? CookieConfig.defaultSameSite,\n secure: AsgardeoExpressClient._clientConfig.cookieConfig?.secure ?? CookieConfig.defaultSecure,\n });\n res.redirect(url);\n\n next && typeof next === 'function' && next();\n }\n };\n\n const authResponse: TokenResponse = await this._authClient.signIn(\n authRedirectCallback,\n userId,\n req.query.code,\n req.query.session_state,\n req.query.state,\n signInConfig,\n );\n\n if (authResponse.accessToken || authResponse.idToken) {\n return authResponse;\n } else {\n return {\n accessToken: '',\n createdAt: 0,\n expiresIn: '',\n idToken: '',\n refreshToken: '',\n scope: '',\n tokenType: '',\n };\n }\n }\n\n public async signOut(userId: string): Promise<string> {\n return this._authClient.signOut(userId);\n }\n\n public async isSignedIn(userId: string): Promise<boolean> {\n return this._authClient.isSignedIn(userId);\n }\n\n public async getIdToken(userId: string): Promise<string> {\n return this._authClient.getIdToken(userId);\n }\n\n public async getUser(userId: string): Promise<User> {\n return this._authClient.getUser(userId);\n }\n\n public async getOpenIDProviderEndpoints(): Promise<OIDCEndpoints> {\n return this._authClient.getOpenIDProviderEndpoints();\n }\n\n public async getDecodedIdToken(userId?: string): Promise<IdToken> {\n return this._authClient.getDecodedIdToken(userId);\n }\n\n public async getAccessToken(userId?: string): Promise<string> {\n return this._authClient.getAccessToken(userId);\n }\n\n public async exchangeToken(config: TokenExchangeRequestConfig, userId?: string): Promise<TokenResponse | Response> {\n return this._authClient.exchangeToken(config, userId);\n }\n\n public async reInitialize(config: Partial<AuthClientConfig>): Promise<void> {\n return this._authClient.reInitialize(config);\n }\n\n public async revokeAccessToken(userId?: string): Promise<Response> {\n return this._authClient.revokeAccessToken(userId);\n }\n\n public static didSignOutFail(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.didSignOutFail(afterSignOutUrl);\n }\n\n public static isSignOutSuccessful(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);\n }\n\n public static protectRoute(\n callback: UnauthenticatedCallback,\n ): (req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void> {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-PR-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return protectRoute(this._instance, callback);\n }\n\n public static asgardeoExpressAuth(\n onSignIn: (response: TokenResponse) => void,\n onSignOut: () => void,\n onError: (exception: AsgardeoAuthException) => void,\n ): any {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-AEA-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return asgardeoExpressAuth(this._instance, AsgardeoExpressClient._clientConfig, onSignIn, onSignOut, onError);\n }\n\n public async getStorageManager() {\n return this._authClient.getStorageManager();\n }\n}\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport enum CookieConfig {\n defaultMaxAge = 90000,\n defaultHttpOnly = 'true',\n defaultSameSite = 'lax',\n defaultSecure = 'false'\n}\n\nexport const DEFAULT_LOGIN_PATH = \"/login\";\n\nexport const DEFAULT_LOGOUT_PATH = \"/logout\";\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport express from 'express';\nimport {AsgardeoExpressClient} from '../client';\nimport {UnauthenticatedCallback} from '../models';\nimport {Logger} from '@asgardeo/node';\n\nexport const protectRoute = (\n asgardeoExpressClient: AsgardeoExpressClient,\n callback: UnauthenticatedCallback,\n): ((req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void>) => {\n return async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n Logger.error('No session ID found in the request cookies');\n\n if (callback(res, 'Unauthenticated')) {\n return;\n }\n\n return next();\n } else {\n //validate the cookie\n const isCookieValid = await asgardeoExpressClient.isSignedIn(req.cookies.ASGARDEO_SESSION_ID);\n if (isCookieValid) {\n return next();\n } else {\n Logger.error('Invalid session ID found in the request cookies');\n if (callback(res, 'Invalid session cookie')) {\n return;\n }\n\n return next();\n }\n }\n };\n};\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport { AsgardeoAuthException, Storage, TokenResponse, Logger } from \"@asgardeo/node\";\nimport express from \"express\";\nimport { AsgardeoExpressClient } from \"../client\";\nimport { DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH } from \"../constants\";\nimport { ExpressClientConfig } from \"../models\";\n\nexport const asgardeoExpressAuth = (\n asgardeoExpressClient: AsgardeoExpressClient,\n config: ExpressClientConfig,\n onSignIn: (res: express.Response, tokenResponse: TokenResponse) => void,\n onSignOut: (res: express.Response) => void,\n onError: (res: express.Response, exception: AsgardeoAuthException) => void\n): any => {\n //Create the router\n const router = new express.Router();\n\n //Patch AuthClient to the request and the response\n router.use(async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n req.asgardeoAuth = asgardeoExpressClient;\n res.asgardeoAuth = asgardeoExpressClient;\n next();\n });\n\n //Patch in '/login' route\n router.get(\n config.loginPath || DEFAULT_LOGIN_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n try {\n const response: TokenResponse = await asgardeoExpressClient.signIn(req, res, next, config.signInConfig);\n if (response.accessToken || response.idToken) {\n onSignIn(res, response);\n }\n } catch (e: any) {\n Logger.error(e.message);\n onError(res, e);\n }\n }\n );\n\n //Patch in '/logout' route\n router.get(\n config.logoutPath || DEFAULT_LOGOUT_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n //Check if it is a logout success response\n if (req.query.state === \"sign_out_success\") {\n onSignOut(res);\n\n return;\n }\n\n //Check if the cookie exists\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n onError(\n res,\n new AsgardeoAuthException(\n \"EXPRESS-AUTH_MW-LOGOUT-NF01\",\n \"No cookie found in the request\",\n \"No cookie was sent with the request. The user may not have signed in yet.\"\n )\n );\n\n return;\n } else {\n //Get the signout URL\n try {\n const signOutURL = await req.asgardeoAuth.signOut(req.cookies.ASGARDEO_SESSION_ID);\n if (signOutURL) {\n res.cookie(\"ASGARDEO_SESSION_ID\", null, { maxAge: 0 });\n res.redirect(signOutURL);\n\n return;\n }\n } catch (e: any) {\n onError(res, e);\n\n return;\n }\n }\n }\n );\n\n return router;\n};\n", "export class ExpressUtils {\n\n private static readonly AUTH_CODE_REGEXP: RegExp = /[?&]error=[^&]+/;\n\n /**\n * Util function to check if the URL contains an error.\n *\n * @param url - URL to be checked.\n *\n * @returns {boolean} - True if the URL contains an error.\n */\n public static hasErrorInURL(url: string): boolean {\n\n return this.AUTH_CODE_REGEXP.test(url);\n }\n}\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport * from \"./__legacy__/models\";\nexport * from \"./__legacy__/client\";\n\nexport * from '@asgardeo/node';\n"],
4
+ "sourcesContent": ["/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport {\n LegacyAsgardeoNodeClient,\n AuthClientConfig,\n AuthURLCallback,\n TokenResponse,\n Storage,\n User,\n OIDCEndpoints,\n IdToken,\n TokenExchangeRequestConfig,\n AsgardeoAuthException,\n Logger,\n} from '@asgardeo/node';\nimport {CookieConfig, DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH} from './constants';\nimport {ExpressClientConfig, UnauthenticatedCallback} from './models';\nimport express from 'express';\nimport {v4 as uuidv4} from 'uuid';\nimport {asgardeoExpressAuth, protectRoute} from './middleware';\nimport {ExpressUtils} from './utils/express-utils';\n\nexport class AsgardeoExpressClient {\n private _authClient: LegacyAsgardeoNodeClient<AuthClientConfig>;\n private _storage?: Storage;\n private static _clientConfig: ExpressClientConfig;\n\n private static _instance: AsgardeoExpressClient;\n\n private constructor(config: ExpressClientConfig, storage?: Storage) {\n //Set the client config\n AsgardeoExpressClient._clientConfig = {...config};\n\n //Add the afterSignInUrl and afterSignOutUrl\n //Add custom paths if the user has already declared any or else use the defaults\n const nodeClientConfig: AuthClientConfig = {\n ...config,\n afterSignInUrl: config.appURL + (config.loginPath || DEFAULT_LOGIN_PATH),\n afterSignOutUrl: config.appURL + (config.logoutPath || DEFAULT_LOGOUT_PATH),\n };\n\n //Initialize the user provided storage if there is any\n if (storage) {\n Logger.debug('Initializing user provided storage');\n this._storage = storage;\n }\n\n //Initialize the Auth Client\n this._authClient = new LegacyAsgardeoNodeClient();\n this._authClient.initialize(nodeClientConfig, this._storage);\n }\n\n public static getInstance(config: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient;\n public static getInstance(): AsgardeoExpressClient;\n public static getInstance(config?: ExpressClientConfig, storage?: Storage): AsgardeoExpressClient {\n //Create a new instance if its not instantiated already\n if (!AsgardeoExpressClient._instance && config) {\n AsgardeoExpressClient._instance = new AsgardeoExpressClient(config, storage);\n Logger.debug('Initialized AsgardeoExpressClient successfully');\n }\n\n if (!AsgardeoExpressClient._instance && !config) {\n throw Error(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-GI1-NF01',\n 'User configuration is not found',\n 'User config has not been passed to initialize AsgardeoExpressClient',\n ).toString(),\n );\n }\n\n return AsgardeoExpressClient._instance;\n }\n\n public async signIn(\n req: express.Request,\n res: express.Response,\n next: express.nextFunction,\n signInConfig?: Record<string, string | boolean>,\n ): Promise<TokenResponse> {\n if (ExpressUtils.hasErrorInURL(req.originalUrl)) {\n return Promise.reject(\n new AsgardeoAuthException(\n 'EXPRESS-CLIENT-SI-IV01',\n 'Invalid login request URL',\n 'Login request contains an error query parameter in the URL',\n ),\n );\n }\n\n //Check if the user has a valid user ID and if not create one\n let userId = req.cookies.ASGARDEO_SESSION_ID;\n if (!userId) {\n userId = uuidv4();\n }\n\n //Handle signIn() callback\n const authRedirectCallback = (url: string) => {\n if (url) {\n //DEBUG\n Logger.debug('Redirecting to: ' + url);\n res.cookie('ASGARDEO_SESSION_ID', userId, {\n maxAge: AsgardeoExpressClient._clientConfig.cookieConfig?.maxAge\n ? AsgardeoExpressClient._clientConfig.cookieConfig.maxAge\n : CookieConfig.defaultMaxAge,\n httpOnly: AsgardeoExpressClient._clientConfig.cookieConfig?.httpOnly ?? CookieConfig.defaultHttpOnly,\n sameSite: AsgardeoExpressClient._clientConfig.cookieConfig?.sameSite ?? CookieConfig.defaultSameSite,\n secure: AsgardeoExpressClient._clientConfig.cookieConfig?.secure ?? CookieConfig.defaultSecure,\n });\n res.redirect(url);\n\n next && typeof next === 'function' && next();\n }\n };\n\n const authResponse: TokenResponse = await this._authClient.signIn(\n authRedirectCallback,\n userId,\n req.query.code,\n req.query.session_state,\n req.query.state,\n signInConfig,\n );\n\n if (authResponse.accessToken || authResponse.idToken) {\n return authResponse;\n } else {\n return {\n accessToken: '',\n createdAt: 0,\n expiresIn: '',\n idToken: '',\n refreshToken: '',\n scope: '',\n tokenType: '',\n };\n }\n }\n\n public async signOut(userId: string): Promise<string> {\n return this._authClient.signOut(userId);\n }\n\n public async isSignedIn(userId: string): Promise<boolean> {\n return this._authClient.isSignedIn(userId);\n }\n\n public async getIdToken(userId: string): Promise<string> {\n return this._authClient.getIdToken(userId);\n }\n\n public async getUser(userId: string): Promise<User> {\n return this._authClient.getUser(userId);\n }\n\n public async getOpenIDProviderEndpoints(): Promise<OIDCEndpoints> {\n return this._authClient.getOpenIDProviderEndpoints();\n }\n\n public async getDecodedIdToken(userId?: string): Promise<IdToken> {\n return this._authClient.getDecodedIdToken(userId);\n }\n\n public async getAccessToken(userId?: string): Promise<string> {\n return this._authClient.getAccessToken(userId);\n }\n\n public async exchangeToken(config: TokenExchangeRequestConfig, userId?: string): Promise<TokenResponse | Response> {\n return this._authClient.exchangeToken(config, userId);\n }\n\n public async reInitialize(config: Partial<AuthClientConfig>): Promise<void> {\n return this._authClient.reInitialize(config);\n }\n\n public async revokeAccessToken(userId?: string): Promise<Response> {\n return this._authClient.revokeAccessToken(userId);\n }\n\n public static didSignOutFail(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.didSignOutFail(afterSignOutUrl);\n }\n\n public static isSignOutSuccessful(afterSignOutUrl: string): boolean {\n return LegacyAsgardeoNodeClient.isSignOutSuccessful(afterSignOutUrl);\n }\n\n public static protectRoute(\n callback: UnauthenticatedCallback,\n ): (req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void> {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-PR-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return protectRoute(this._instance, callback);\n }\n\n public static asgardeoExpressAuth(\n onSignIn: (response: TokenResponse) => void,\n onSignOut: () => void,\n onError: (exception: AsgardeoAuthException) => void,\n ): any {\n if (!this._instance) {\n throw new AsgardeoAuthException(\n 'EXPRESS-CLIENT-AEA-NF01',\n 'AsgardeoExpressClient is not instantiated',\n 'Create an instance of AsgardeoExpressClient before using calling this method.',\n );\n }\n\n return asgardeoExpressAuth(this._instance, AsgardeoExpressClient._clientConfig, onSignIn, onSignOut, onError);\n }\n\n public async getStorageManager() {\n return this._authClient.getStorageManager();\n }\n}\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport enum CookieConfig {\n defaultMaxAge = 90000,\n defaultHttpOnly = 'true',\n defaultSameSite = 'lax',\n defaultSecure = 'false'\n}\n\nexport const DEFAULT_LOGIN_PATH = \"/login\";\n\nexport const DEFAULT_LOGOUT_PATH = \"/logout\";\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport express from 'express';\nimport {AsgardeoExpressClient} from '../client';\nimport {UnauthenticatedCallback} from '../models';\nimport {Logger} from '@asgardeo/node';\n\nexport const protectRoute = (\n asgardeoExpressClient: AsgardeoExpressClient,\n callback: UnauthenticatedCallback,\n): ((req: express.Request, res: express.Response, next: express.nextFunction) => Promise<void>) => {\n return async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n Logger.error('No session ID found in the request cookies');\n\n if (callback(res, 'Unauthenticated')) {\n return;\n }\n\n return next();\n } else {\n //validate the cookie\n const isCookieValid = await asgardeoExpressClient.isSignedIn(req.cookies.ASGARDEO_SESSION_ID);\n if (isCookieValid) {\n return next();\n } else {\n Logger.error('Invalid session ID found in the request cookies');\n if (callback(res, 'Invalid session cookie')) {\n return;\n }\n\n return next();\n }\n }\n };\n};\n", "/**\n * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.com) All Rights Reserved.\n *\n * WSO2 Inc. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nimport { AsgardeoAuthException, Storage, TokenResponse, Logger } from \"@asgardeo/node\";\nimport express from \"express\";\nimport { AsgardeoExpressClient } from \"../client\";\nimport { DEFAULT_LOGIN_PATH, DEFAULT_LOGOUT_PATH } from \"../constants\";\nimport { ExpressClientConfig } from \"../models\";\n\nexport const asgardeoExpressAuth = (\n asgardeoExpressClient: AsgardeoExpressClient,\n config: ExpressClientConfig,\n onSignIn: (res: express.Response, tokenResponse: TokenResponse) => void,\n onSignOut: (res: express.Response) => void,\n onError: (res: express.Response, exception: AsgardeoAuthException) => void\n): any => {\n //Create the router\n const router = new express.Router();\n\n //Patch AuthClient to the request and the response\n router.use(async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n req.asgardeoAuth = asgardeoExpressClient;\n res.asgardeoAuth = asgardeoExpressClient;\n next();\n });\n\n //Patch in '/login' route\n router.get(\n config.loginPath || DEFAULT_LOGIN_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n try {\n const response: TokenResponse = await asgardeoExpressClient.signIn(req, res, next, config.signInConfig);\n if (response.accessToken || response.idToken) {\n onSignIn(res, response);\n }\n } catch (e: any) {\n Logger.error(e.message);\n onError(res, e);\n }\n }\n );\n\n //Patch in '/logout' route\n router.get(\n config.logoutPath || DEFAULT_LOGOUT_PATH,\n async (req: express.Request, res: express.Response, next: express.nextFunction): Promise<void> => {\n //Check if it is a logout success response\n if (req.query.state === \"sign_out_success\") {\n onSignOut(res);\n\n return;\n }\n\n //Check if the cookie exists\n if (req.cookies.ASGARDEO_SESSION_ID === undefined) {\n onError(\n res,\n new AsgardeoAuthException(\n \"EXPRESS-AUTH_MW-LOGOUT-NF01\",\n \"No cookie found in the request\",\n \"No cookie was sent with the request. The user may not have signed in yet.\"\n )\n );\n\n return;\n } else {\n //Get the signout URL\n try {\n const signOutURL = await req.asgardeoAuth.signOut(req.cookies.ASGARDEO_SESSION_ID);\n if (signOutURL) {\n res.cookie(\"ASGARDEO_SESSION_ID\", null, { maxAge: 0 });\n res.redirect(signOutURL);\n\n return;\n }\n } catch (e: any) {\n onError(res, e);\n\n return;\n }\n }\n }\n );\n\n return router;\n};\n", "export class ExpressUtils {\n\n private static readonly AUTH_CODE_REGEXP: RegExp = /[?&]error=[^&]+/;\n\n /**\n * Util function to check if the URL contains an error.\n *\n * @param url - URL to be checked.\n *\n * @returns {boolean} - True if the URL contains an error.\n */\n public static hasErrorInURL(url: string): boolean {\n\n return this.AUTH_CODE_REGEXP.test(url);\n }\n}\n", "/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\nexport * from './__legacy__/models';\nexport * from './__legacy__/client';\n\nexport * from '@asgardeo/node';\n"],
5
5
  "mappings": ";;;;;AAkBA;AAAA,EACE;AAAA,EASA,yBAAAA;AAAA,EACA,UAAAC;AAAA,OACK;;;ACLA,IAAM,qBAAqB;AAE3B,IAAM,sBAAsB;;;ADOnC,SAAQ,MAAM,cAAa;;;AEb3B,SAAQ,cAAa;AAEd,IAAM,eAAe,CAC1B,uBACA,aACiG;AACjG,SAAO,OAAO,KAAsB,KAAuB,SAA8C;AACvG,QAAI,IAAI,QAAQ,wBAAwB,QAAW;AACjD,aAAO,MAAM,4CAA4C;AAEzD,UAAI,SAAS,KAAK,iBAAiB,GAAG;AACpC;AAAA,MACF;AAEA,aAAO,KAAK;AAAA,IACd,OA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,UAAU,WAAW,OAAO;AAAA,EAC9G;AAAA,EAEA,MAAa,oBAAoB;AAC/B,WAAO,KAAK,YAAY,kBAAkB;AAAA,EAC5C;AACF;AAnME,cAHW,wBAGI;AAEf,cALW,wBAKI;AALV,IAAM,wBAAN;;;AKjBP,cAAc;",
6
6
  "names": ["AsgardeoAuthException", "Logger", "Logger", "Logger", "Logger", "AsgardeoAuthException"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgardeo/express",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "Express.js implementation of Asgardeo JavaScript SDK.",
5
5
  "keywords": [
6
6
  "asgardeo",
@@ -38,7 +38,7 @@
38
38
  "@wso2/prettier-config": "git+https://github.com/brionmario/wso2-ui-configs.git#a1fc6eb570653c999828aea9f5027cba06af4391&path:packages/prettier-config",
39
39
  "esbuild": "0.25.9",
40
40
  "eslint": "8.57.0",
41
- "express": "5.1.0",
41
+ "express": "5.2.1",
42
42
  "prettier": "2.6.2",
43
43
  "rimraf": "6.1.0",
44
44
  "typescript": "5.7.2",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "uuid": "11.1.0",
49
- "@asgardeo/node": "0.0.49"
49
+ "@asgardeo/node": "0.0.51"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "express": ">=4.21.2"
@@ -59,7 +59,7 @@
59
59
  "clean": "rimraf dist",
60
60
  "fix:lint": "eslint . --ext .js,.jsx,.ts,.tsx,.cjs,.mjs",
61
61
  "lint": "eslint . --ext .js,.jsx,.ts,.tsx,.cjs,.mjs",
62
- "test": "vitest",
62
+ "test": "vitest --passWithNoTests",
63
63
  "typecheck": "tsc -p tsconfig.lib.json"
64
64
  }
65
65
  }