Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cookies type in oauth2provider #969

Open
wants to merge 2 commits into
base: 21.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [unreleased]

## [21.1.1] - 2024-12-27

- Fixes type of `cookies` to `string[]` instead of `string` in:
- Return type of `authorization` in `RecipeInterface` in `oauth2provider` recipe
- Return type of `authGET` in `APIInterface` in `oauth2provider` recipe
- Return type of `loginGET` in `APIInterface` in `oauth2provider` recipe

## [21.1.0] - 2024-11-19

- Adds `getCookieNameForTokenType` config option to allow customizing the cookie name for a token type.
Expand Down
10 changes: 5 additions & 5 deletions lib/build/recipe/oauth2provider/api/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ export declare function loginGET({
loginChallenge: string;
session?: SessionContainerInterface;
shouldTryRefresh: boolean;
cookies?: string;
cookies?: string[];
userContext: UserContext;
isDirectCall: boolean;
}): Promise<
| ErrorOAuth2
| {
status: string;
redirectTo: string;
cookies: string | undefined;
cookies: string[] | undefined;
}
| {
redirectTo: string;
cookies: string | undefined;
cookies: string[] | undefined;
status?: undefined;
}
>;
Expand All @@ -41,7 +41,7 @@ export declare function handleLoginInternalRedirects({
}: {
response: {
redirectTo: string;
cookies?: string;
cookies?: string[];
};
recipeImplementation: RecipeInterface;
session?: SessionContainerInterface;
Expand All @@ -51,7 +51,7 @@ export declare function handleLoginInternalRedirects({
}): Promise<
| {
redirectTo: string;
cookies?: string;
cookies?: string[];
}
| ErrorOAuth2
>;
Expand Down
12 changes: 8 additions & 4 deletions lib/build/recipe/oauth2provider/api/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,17 @@ function getMergedCookies({ origCookies = "", newCookies }) {
.join(";");
}
function mergeSetCookieHeaders(setCookie1, setCookie2) {
if (!setCookie1) {
return setCookie2 || "";
if (setCookie1 == undefined || setCookie1.length === 0) {
return setCookie2 === undefined ? [] : setCookie2;
}
if (!setCookie2 || setCookie1 === setCookie2) {
if (
!setCookie2 ||
(new Set(setCookie1).size === new Set(setCookie2).size &&
new Set(setCookie1).size === new Set([...setCookie1, ...setCookie2]).size)
) {
return setCookie1;
}
return `${setCookie1}, ${setCookie2}`;
return [...setCookie1, ...setCookie2];
}
function isLoginInternalRedirect(redirectTo) {
const { apiDomain, apiBasePath } = supertokens_1.default.getInstanceOrThrowError().appInfo;
Expand Down
6 changes: 3 additions & 3 deletions lib/build/recipe/oauth2provider/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export declare type RecipeInterface = {
}): Promise<
| {
redirectTo: string;
cookies: string | undefined;
cookies: string[] | undefined;
}
| ErrorOAuth2
>;
Expand Down Expand Up @@ -379,7 +379,7 @@ export declare type APIInterface = {
}) => Promise<
| {
frontendRedirectTo: string;
cookies?: string;
cookies?: string[];
}
| ErrorOAuth2
| GeneralErrorResponse
Expand All @@ -396,7 +396,7 @@ export declare type APIInterface = {
}) => Promise<
| {
redirectTo: string;
cookies?: string;
cookies?: string[];
}
| ErrorOAuth2
| GeneralErrorResponse
Expand Down
2 changes: 1 addition & 1 deletion lib/build/version.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/build/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions lib/ts/recipe/oauth2provider/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function loginGET({
loginChallenge: string;
session?: SessionContainerInterface;
shouldTryRefresh: boolean;
cookies?: string;
cookies?: string[];
userContext: UserContext;
isDirectCall: boolean;
}) {
Expand Down Expand Up @@ -143,7 +143,7 @@ export async function loginGET({
};
}

function getMergedCookies({ origCookies = "", newCookies }: { origCookies?: string; newCookies?: string }): string {
function getMergedCookies({ origCookies = "", newCookies }: { origCookies?: string; newCookies?: string[] }): string {
if (!newCookies) {
return origCookies;
}
Expand All @@ -168,14 +168,18 @@ function getMergedCookies({ origCookies = "", newCookies }: { origCookies?: stri
.join(";");
}

function mergeSetCookieHeaders(setCookie1?: string, setCookie2?: string): string {
if (!setCookie1) {
return setCookie2 || "";
function mergeSetCookieHeaders(setCookie1?: string[], setCookie2?: string[]): string[] {
if (setCookie1 == undefined || setCookie1.length === 0) {
return setCookie2 === undefined ? [] : setCookie2;
}
if (!setCookie2 || setCookie1 === setCookie2) {
if (
!setCookie2 ||
(new Set(setCookie1).size === new Set(setCookie2).size &&
new Set(setCookie1).size === new Set([...setCookie1, ...setCookie2]).size)
) {
return setCookie1;
}
return `${setCookie1}, ${setCookie2}`;
return [...setCookie1, ...setCookie2];
}

function isLoginInternalRedirect(redirectTo: string): boolean {
Expand All @@ -202,13 +206,13 @@ export async function handleLoginInternalRedirects({
cookie = "",
userContext,
}: {
response: { redirectTo: string; cookies?: string };
response: { redirectTo: string; cookies?: string[] };
recipeImplementation: RecipeInterface;
session?: SessionContainerInterface;
shouldTryRefresh: boolean;
cookie?: string;
userContext: UserContext;
}): Promise<{ redirectTo: string; cookies?: string } | ErrorOAuth2> {
}): Promise<{ redirectTo: string; cookies?: string[] } | ErrorOAuth2> {
if (!isLoginInternalRedirect(response.redirectTo)) {
return response;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ts/recipe/oauth2provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export type RecipeInterface = {
cookies: string | undefined;
session: SessionContainerInterface | undefined;
userContext: UserContext;
}): Promise<{ redirectTo: string; cookies: string | undefined } | ErrorOAuth2>;
}): Promise<{ redirectTo: string; cookies: string[] | undefined } | ErrorOAuth2>;
tokenExchange(input: {
authorizationHeader?: string;
body: Record<string, string | undefined>;
Expand Down Expand Up @@ -428,7 +428,7 @@ export type APIInterface = {
session?: SessionContainerInterface;
shouldTryRefresh: boolean;
userContext: UserContext;
}) => Promise<{ frontendRedirectTo: string; cookies?: string } | ErrorOAuth2 | GeneralErrorResponse>);
}) => Promise<{ frontendRedirectTo: string; cookies?: string[] } | ErrorOAuth2 | GeneralErrorResponse>);

authGET:
| undefined
Expand All @@ -439,7 +439,7 @@ export type APIInterface = {
shouldTryRefresh: boolean;
options: APIOptions;
userContext: UserContext;
}) => Promise<{ redirectTo: string; cookies?: string } | ErrorOAuth2 | GeneralErrorResponse>);
}) => Promise<{ redirectTo: string; cookies?: string[] } | ErrorOAuth2 | GeneralErrorResponse>);
tokenPOST:
| undefined
| ((input: {
Expand Down
2 changes: 1 addition & 1 deletion lib/ts/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
export const version = "21.1.0";
export const version = "21.1.1";

export const cdiSupported = ["5.2"];

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertokens-node",
"version": "21.1.0",
"version": "21.1.1",
"description": "NodeJS driver for SuperTokens core",
"main": "index.js",
"scripts": {
Expand Down
Loading