diff --git a/CHANGELOG.md b/CHANGELOG.md index c553b6fdf..d3c5f36c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [unreleased] +## [21.1.0] - 2024-11-19 + +- Adds `getCookieNameForTokenType` config option to allow customizing the cookie name for a token type. +- Adds `getResponseHeaderNameForTokenType` config option to allow customizing the response header name for a token type. + - Please note, that using this will require further customizations on the frontend + ## [21.0.0] - 2024-10-07 - Added OAuth2Provider recipe diff --git a/lib/build/recipe/session/cookieAndHeaders.js b/lib/build/recipe/session/cookieAndHeaders.js index fd45f8f6f..2bf01f8aa 100644 --- a/lib/build/recipe/session/cookieAndHeaders.js +++ b/lib/build/recipe/session/cookieAndHeaders.js @@ -83,7 +83,7 @@ function getCORSAllowedHeaders() { exports.getCORSAllowedHeaders = getCORSAllowedHeaders; function getToken(config, req, tokenType, transferMethod, userContext) { if (transferMethod === "cookie") { - return req.getCookieValue(config.getCookieNameFromTokenType(req, tokenType, userContext)); + return req.getCookieValue(config.getCookieNameForTokenType(req, tokenType, userContext)); } else if (transferMethod === "header") { const value = req.getHeaderValue(constants_2.authorizationHeaderKey); if (value === undefined || !value.startsWith("Bearer ")) { @@ -101,7 +101,7 @@ function setToken(config, res, tokenType, value, expires, transferMethod, req, u setCookie( config, res, - config.getCookieNameFromTokenType(req, tokenType, userContext), + config.getCookieNameForTokenType(req, tokenType, userContext), value, expires, tokenType === "refresh" ? "refreshTokenPath" : "accessTokenPath", @@ -220,7 +220,7 @@ function hasMultipleCookiesForTokenType(config, req, tokenType, userContext) { return false; } const cookies = parseCookieStringFromRequestHeaderAllowingDuplicates(cookieString); - const cookieName = config.getCookieNameFromTokenType(req, tokenType, userContext); + const cookieName = config.getCookieNameForTokenType(req, tokenType, userContext); return cookies[cookieName] !== undefined && cookies[cookieName].length > 1; } exports.hasMultipleCookiesForTokenType = hasMultipleCookiesForTokenType; diff --git a/lib/build/recipe/session/types.d.ts b/lib/build/recipe/session/types.d.ts index 186fab33d..8a1d06794 100644 --- a/lib/build/recipe/session/types.d.ts +++ b/lib/build/recipe/session/types.d.ts @@ -51,7 +51,7 @@ export declare type TypeInput = { forCreateNewSession: boolean; userContext: UserContext; }) => TokenTransferMethod | "any"; - getCookieNameFromTokenType?: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; + getCookieNameForTokenType?: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; getResponseHeaderNameForTokenType?: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; errorHandlers?: ErrorHandlers; antiCsrf?: "VIA_TOKEN" | "VIA_CUSTOM_HEADER" | "NONE"; @@ -76,7 +76,7 @@ export declare type TypeNormalisedInput = { userContext: UserContext; }) => "strict" | "lax" | "none"; cookieSecure: boolean; - getCookieNameFromTokenType: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; + getCookieNameForTokenType: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; getResponseHeaderNameForTokenType: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; sessionExpiredStatusCode: number; errorHandlers: NormalisedErrorHandlers; diff --git a/lib/build/recipe/session/utils.d.ts b/lib/build/recipe/session/utils.d.ts index ad33595c7..02fa11722 100644 --- a/lib/build/recipe/session/utils.d.ts +++ b/lib/build/recipe/session/utils.d.ts @@ -75,7 +75,7 @@ export declare function validateClaimsInPayload( reason: import("../../types").JSONValue; }[] >; -export declare function getCookieNameFromTokenType( +export declare function getCookieNameForTokenType( _req: BaseRequest, tokenType: TokenType ): "sAccessToken" | "sRefreshToken"; diff --git a/lib/build/recipe/session/utils.js b/lib/build/recipe/session/utils.js index de84f8407..501b39f96 100644 --- a/lib/build/recipe/session/utils.js +++ b/lib/build/recipe/session/utils.js @@ -19,7 +19,7 @@ var __importDefault = return mod && mod.__esModule ? mod : { default: mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.getResponseHeaderNameForTokenType = exports.getCookieNameFromTokenType = exports.validateClaimsInPayload = exports.getRequiredClaimValidators = exports.setAccessTokenInResponse = exports.normaliseSameSiteOrThrowError = exports.validateAndNormaliseUserInput = exports.getURLProtocol = exports.normaliseSessionScopeOrThrowError = exports.sendTokenTheftDetectedResponse = exports.sendInvalidClaimResponse = exports.sendUnauthorisedResponse = exports.sendTryRefreshTokenResponse = void 0; +exports.getResponseHeaderNameForTokenType = exports.getCookieNameForTokenType = exports.validateClaimsInPayload = exports.getRequiredClaimValidators = exports.setAccessTokenInResponse = exports.normaliseSameSiteOrThrowError = exports.validateAndNormaliseUserInput = exports.getURLProtocol = exports.normaliseSessionScopeOrThrowError = exports.sendTokenTheftDetectedResponse = exports.sendInvalidClaimResponse = exports.sendUnauthorisedResponse = exports.sendTryRefreshTokenResponse = void 0; const cookieAndHeaders_1 = require("./cookieAndHeaders"); const recipe_1 = __importDefault(require("./recipe")); const constants_1 = require("./constants"); @@ -221,11 +221,11 @@ function validateAndNormaliseUserInput(recipeInstance, appInfo, config) { (config === null || config === void 0 ? void 0 : config.getTokenTransferMethod) === undefined ? defaultGetTokenTransferMethod : config.getTokenTransferMethod, - getCookieNameFromTokenType: - (_d = config === null || config === void 0 ? void 0 : config.getCookieNameFromTokenType) !== null && + getCookieNameForTokenType: + (_d = config === null || config === void 0 ? void 0 : config.getCookieNameForTokenType) !== null && _d !== void 0 ? _d - : getCookieNameFromTokenType, + : getCookieNameForTokenType, getResponseHeaderNameForTokenType: (_e = config === null || config === void 0 ? void 0 : config.getResponseHeaderNameForTokenType) !== null && _e !== void 0 @@ -341,7 +341,7 @@ function defaultGetTokenTransferMethod({ req, forCreateNewSession }) { return "any"; } } -function getCookieNameFromTokenType(_req, tokenType) { +function getCookieNameForTokenType(_req, tokenType) { switch (tokenType) { case "access": return constants_1.accessTokenCookieKey; @@ -351,7 +351,7 @@ function getCookieNameFromTokenType(_req, tokenType) { throw new Error("Unknown token type, should never happen."); } } -exports.getCookieNameFromTokenType = getCookieNameFromTokenType; +exports.getCookieNameForTokenType = getCookieNameForTokenType; function getResponseHeaderNameForTokenType(_req, tokenType) { switch (tokenType) { case "access": diff --git a/lib/build/version.d.ts b/lib/build/version.d.ts index e151552ba..b4ea16c58 100644 --- a/lib/build/version.d.ts +++ b/lib/build/version.d.ts @@ -1,4 +1,4 @@ // @ts-nocheck -export declare const version = "21.0.0"; +export declare const version = "21.1.0"; export declare const cdiSupported: string[]; export declare const dashboardVersion = "0.13"; diff --git a/lib/build/version.js b/lib/build/version.js index 5fab53774..2d83d58ed 100644 --- a/lib/build/version.js +++ b/lib/build/version.js @@ -15,7 +15,7 @@ exports.dashboardVersion = exports.cdiSupported = exports.version = void 0; * License for the specific language governing permissions and limitations * under the License. */ -exports.version = "21.0.0"; +exports.version = "21.1.0"; exports.cdiSupported = ["5.2"]; // Note: The actual script import for dashboard uses v{DASHBOARD_VERSION} exports.dashboardVersion = "0.13"; diff --git a/lib/ts/recipe/session/cookieAndHeaders.ts b/lib/ts/recipe/session/cookieAndHeaders.ts index c80f604ba..331644b01 100644 --- a/lib/ts/recipe/session/cookieAndHeaders.ts +++ b/lib/ts/recipe/session/cookieAndHeaders.ts @@ -98,7 +98,7 @@ export function getToken( userContext: UserContext ) { if (transferMethod === "cookie") { - return req.getCookieValue(config.getCookieNameFromTokenType(req, tokenType, userContext)); + return req.getCookieValue(config.getCookieNameForTokenType(req, tokenType, userContext)); } else if (transferMethod === "header") { const value = req.getHeaderValue(authorizationHeaderKey); if (value === undefined || !value.startsWith("Bearer ")) { @@ -126,7 +126,7 @@ export function setToken( setCookie( config, res, - config.getCookieNameFromTokenType(req, tokenType, userContext), + config.getCookieNameForTokenType(req, tokenType, userContext), value, expires, tokenType === "refresh" ? "refreshTokenPath" : "accessTokenPath", @@ -274,7 +274,7 @@ export function hasMultipleCookiesForTokenType( } const cookies = parseCookieStringFromRequestHeaderAllowingDuplicates(cookieString); - const cookieName = config.getCookieNameFromTokenType(req, tokenType, userContext); + const cookieName = config.getCookieNameForTokenType(req, tokenType, userContext); return cookies[cookieName] !== undefined && cookies[cookieName].length > 1; } diff --git a/lib/ts/recipe/session/types.ts b/lib/ts/recipe/session/types.ts index 5d63faff2..a05b172c1 100644 --- a/lib/ts/recipe/session/types.ts +++ b/lib/ts/recipe/session/types.ts @@ -74,7 +74,7 @@ export type TypeInput = { forCreateNewSession: boolean; userContext: UserContext; }) => TokenTransferMethod | "any"; - getCookieNameFromTokenType?: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; + getCookieNameForTokenType?: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; getResponseHeaderNameForTokenType?: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; errorHandlers?: ErrorHandlers; @@ -101,7 +101,7 @@ export type TypeNormalisedInput = { userContext: UserContext; }) => "strict" | "lax" | "none"; cookieSecure: boolean; - getCookieNameFromTokenType: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; + getCookieNameForTokenType: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; getResponseHeaderNameForTokenType: (req: BaseRequest, tokenType: TokenType, userContext: UserContext) => string; sessionExpiredStatusCode: number; errorHandlers: NormalisedErrorHandlers; diff --git a/lib/ts/recipe/session/utils.ts b/lib/ts/recipe/session/utils.ts index 3238a4689..02c018437 100644 --- a/lib/ts/recipe/session/utils.ts +++ b/lib/ts/recipe/session/utils.ts @@ -302,7 +302,7 @@ export function validateAndNormaliseUserInput( config?.getTokenTransferMethod === undefined ? defaultGetTokenTransferMethod : config.getTokenTransferMethod, - getCookieNameFromTokenType: config?.getCookieNameFromTokenType ?? getCookieNameFromTokenType, + getCookieNameForTokenType: config?.getCookieNameForTokenType ?? getCookieNameForTokenType, getResponseHeaderNameForTokenType: config?.getResponseHeaderNameForTokenType ?? getResponseHeaderNameForTokenType, cookieDomain, @@ -435,7 +435,7 @@ function defaultGetTokenTransferMethod({ } } -export function getCookieNameFromTokenType(_req: BaseRequest, tokenType: TokenType) { +export function getCookieNameForTokenType(_req: BaseRequest, tokenType: TokenType) { switch (tokenType) { case "access": return accessTokenCookieKey; diff --git a/lib/ts/version.ts b/lib/ts/version.ts index a072bf0ae..7c52a9640 100644 --- a/lib/ts/version.ts +++ b/lib/ts/version.ts @@ -12,7 +12,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -export const version = "21.0.0"; +export const version = "21.1.0"; export const cdiSupported = ["5.2"]; diff --git a/package-lock.json b/package-lock.json index 918e552e8..bc0641fa8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supertokens-node", - "version": "21.0.0", + "version": "21.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "supertokens-node", - "version": "21.0.0", + "version": "21.1.0", "license": "Apache-2.0", "dependencies": { "buffer": "^6.0.3", diff --git a/package.json b/package.json index 885295016..06454f21c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supertokens-node", - "version": "21.0.0", + "version": "21.1.0", "description": "NodeJS driver for SuperTokens core", "main": "index.js", "scripts": { diff --git a/test/test-server/src/index.ts b/test/test-server/src/index.ts index 3fc101557..cadba3338 100644 --- a/test/test-server/src/index.ts +++ b/test/test-server/src/index.ts @@ -33,7 +33,7 @@ import Multitenancy from "../../../recipe/multitenancy"; import Passwordless from "../../../recipe/passwordless"; import Session from "../../../recipe/session"; import { verifySession } from "../../../recipe/session/framework/express"; -import { getResponseHeaderNameForTokenType, getCookieNameFromTokenType } from "../../../lib/build/recipe/session/utils"; +import { getResponseHeaderNameForTokenType, getCookieNameForTokenType } from "../../../lib/build/recipe/session/utils"; import ThirdParty from "../../../recipe/thirdparty"; import TOTP from "../../../recipe/totp"; import OAuth2Provider from "../../../recipe/oauth2provider"; @@ -148,15 +148,13 @@ function initST(config: any) { recipeList.push( Session.init({ ...config, - getResponseHeaderNameForTokenType: callbackWithLog( + getResponseHeaderNameForTokenType: loggingOverrideFuncSync( "Session.getResponseHeaderNameForTokenType", - config?.getResponseHeaderNameForTokenType, getResponseHeaderNameForTokenType ), - getCookieNameFromTokenType: callbackWithLog( - "Session.getCookieNameFromTokenType", - config?.getCookieNameFromTokenType, - getCookieNameFromTokenType + getCookieNameForTokenType: loggingOverrideFuncSync( + "Session.getCookieNameForTokenType", + getCookieNameForTokenType ), override: { apis: overrideBuilderWithLogging("Session.override.apis", config?.override?.apis), @@ -230,9 +228,9 @@ function initST(config: any) { getEmailForRecipeUserId: callbackWithLog( "EmailVerification.getEmailForRecipeUserId", config?.getEmailForRecipeUserId, - () => { - status: "UNKNOWN_USER_ID_ERROR"; - } + () => ({ + status: "UNKNOWN_USER_ID_ERROR", + }) ), override: { apis: overrideBuilderWithLogging("EmailVerification.override.apis", config?.override?.apis), @@ -476,7 +474,7 @@ app.listen(API_PORT, "localhost", () => { logDebugMessage(`node-test-server-server started on localhost:${API_PORT}`); }); -function loggingOverrideFuncSync(name: string, originalImpl: (...args: any[]) => Promise) { +function loggingOverrideFuncSync(name: string, originalImpl: (...args: any[]) => T) { return function (...args: any[]) { logOverrideEvent(name, "CALL", args); try {