Skip to content

Revert "Add support for Federated Connection Access Token (#1911)" #1918

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

Merged
merged 2 commits into from
Feb 17, 2025
Merged
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
2 changes: 1 addition & 1 deletion examples/with-shadcn/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NextRequest } from "next/server"
import { auth0 } from "./lib/auth0"

export async function middleware(request: NextRequest) {
return await auth0.middleware(request);
return await auth0.middleware(request)
}

export const config = {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-shadcn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@auth0/nextjs-auth0": "^4.0.1",
"@auth0/nextjs-auth0": "^4.0.0",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.2",
Expand Down
10 changes: 5 additions & 5 deletions examples/with-shadcn/pnpm-lock.yaml

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

43 changes: 0 additions & 43 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,46 +98,3 @@ export class AccessTokenError extends SdkError {
this.code = code;
}
}

/**
* Enum representing error codes related to federated connection access tokens.
*/
export enum FederatedConnectionAccessTokenErrorCode {
/**
* The session is missing.
*/
MISSING_SESSION = "missing_session",

/**
* The refresh token is missing.
*/
MISSING_REFRESH_TOKEN = "missing_refresh_token",

/**
* Failed to exchange the refresh token.
*/
FAILED_TO_EXCHANGE = "failed_to_exchange_refresh_token"
}

/**
* Error class representing an access token error for federated connections.
* Extends the `SdkError` class.
*/
export class FederatedConnectionsAccessTokenError extends SdkError {
/**
* The error code associated with the access token error.
*/
public code: string;

/**
* Constructs a new `FederatedConnectionsAccessTokenError` instance.
*
* @param code - The error code.
* @param message - The error message.
*/
constructor(code: string, message: string) {
super(message);
this.name = "FederatedConnectionAccessTokenError";
this.code = code;
}
}
227 changes: 1 addition & 226 deletions src/server/auth-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4153,231 +4153,6 @@ ca/T0LLtgmbMmxSv/MmzIg==
});
});
});

describe("getFederatedConnectionTokenSet", async () => {
it("should call for an access token when no federated connection token set in the session", async () => {
const secret = await generateSecret(32);
const transactionStore = new TransactionStore({
secret
});
const sessionStore = new StatelessSessionStore({
secret
});
const fetchSpy = getMockAuthorizationServer({
tokenEndpointResponse: {
token_type: "Bearer",
access_token: DEFAULT.accessToken,
expires_in: 86400 // expires in 10 days
} as oauth.TokenEndpointResponse
});

const authClient = new AuthClient({
transactionStore,
sessionStore,

domain: DEFAULT.domain,
clientId: DEFAULT.clientId,
clientSecret: DEFAULT.clientSecret,

secret,
appBaseUrl: DEFAULT.appBaseUrl,

fetch: fetchSpy
});

const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
const tokenSet = {
accessToken: DEFAULT.accessToken,
refreshToken: DEFAULT.refreshToken,
expiresAt
};

const response = await authClient.getFederatedConnectionTokenSet(
tokenSet,
undefined,
{ connection: "google-oauth2", login_hint: "000100123" }
);
const [error, federatedConnectionTokenSet] = response;
expect(error).toBe(null);
expect(fetchSpy).toHaveBeenCalled();
expect(federatedConnectionTokenSet).toEqual({
accessToken: DEFAULT.accessToken,
connection: "google-oauth2",
expiresAt: expect.any(Number)
});
});

it("should return access token from the session when federated connection token set in the session is not expired", async () => {
const secret = await generateSecret(32);
const transactionStore = new TransactionStore({
secret
});
const sessionStore = new StatelessSessionStore({
secret
});
const fetchSpy = vi.fn();
const authClient = new AuthClient({
transactionStore,
sessionStore,

domain: DEFAULT.domain,
clientId: DEFAULT.clientId,
clientSecret: DEFAULT.clientSecret,

secret,
appBaseUrl: DEFAULT.appBaseUrl,

fetch: fetchSpy
});

const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
const tokenSet = {
accessToken: DEFAULT.accessToken,
refreshToken: DEFAULT.refreshToken,
expiresAt,
};

const response = await authClient.getFederatedConnectionTokenSet(
tokenSet,
{ connection: 'google-oauth2', accessToken: 'fc_at', expiresAt: Math.floor(Date.now() / 1000) + 86400 },
{ connection: "google-oauth2", login_hint: "000100123" }
);
const [error, federatedConnectionTokenSet] = response;
expect(error).toBe(null);
expect(federatedConnectionTokenSet).toEqual({
accessToken: 'fc_at',
connection: "google-oauth2",
expiresAt: expect.any(Number)
});
expect(fetchSpy).not.toHaveBeenCalled();
});

it("should call for an access token when federated connection token set in the session is expired", async () => {
const secret = await generateSecret(32);
const transactionStore = new TransactionStore({
secret
});
const sessionStore = new StatelessSessionStore({
secret
});
const fetchSpy = getMockAuthorizationServer({
tokenEndpointResponse: {
token_type: "Bearer",
access_token: DEFAULT.accessToken,
expires_in: 86400 // expires in 10 days
} as oauth.TokenEndpointResponse
});
const authClient = new AuthClient({
transactionStore,
sessionStore,

domain: DEFAULT.domain,
clientId: DEFAULT.clientId,
clientSecret: DEFAULT.clientSecret,

secret,
appBaseUrl: DEFAULT.appBaseUrl,

fetch: fetchSpy
});

const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
const tokenSet = {
accessToken: DEFAULT.accessToken,
refreshToken: DEFAULT.refreshToken,
expiresAt,
};

const response = await authClient.getFederatedConnectionTokenSet(
tokenSet,
{ connection: 'google-oauth2', accessToken: 'fc_at', expiresAt },
{ connection: "google-oauth2", login_hint: "000100123" }
);
const [error, federatedConnectionTokenSet] = response;
expect(error).toBe(null);
expect(federatedConnectionTokenSet).toEqual({
accessToken: DEFAULT.accessToken,
connection: "google-oauth2",
expiresAt: expect.any(Number)
});
expect(fetchSpy).toHaveBeenCalled();
});

it("should return an error if the discovery endpoint could not be fetched", async () => {
const secret = await generateSecret(32);
const transactionStore = new TransactionStore({
secret
});
const sessionStore = new StatelessSessionStore({
secret
});
const authClient = new AuthClient({
transactionStore,
sessionStore,

domain: DEFAULT.domain,
clientId: DEFAULT.clientId,
clientSecret: DEFAULT.clientSecret,

secret,
appBaseUrl: DEFAULT.appBaseUrl,

fetch: getMockAuthorizationServer({
discoveryResponse: new Response(null, { status: 500 })
})
});

const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
const tokenSet = {
accessToken: DEFAULT.accessToken,
refreshToken: DEFAULT.refreshToken,
expiresAt
};

const [error, federatedConnectionTokenSet] =
await authClient.getFederatedConnectionTokenSet(tokenSet, undefined, {
connection: "google-oauth2"
});
expect(error?.code).toEqual("discovery_error");
expect(federatedConnectionTokenSet).toBeNull();
});

it("should return an error if the token set does not contain a refresh token", async () => {
const secret = await generateSecret(32);
const transactionStore = new TransactionStore({
secret
});
const sessionStore = new StatelessSessionStore({
secret
});
const authClient = new AuthClient({
transactionStore,
sessionStore,

domain: DEFAULT.domain,
clientId: DEFAULT.clientId,
clientSecret: DEFAULT.clientSecret,

secret,
appBaseUrl: DEFAULT.appBaseUrl,

fetch: getMockAuthorizationServer()
});

const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
const tokenSet = {
accessToken: DEFAULT.accessToken,
expiresAt
};

const [error, federatedConnectionTokenSet] =
await authClient.getFederatedConnectionTokenSet(tokenSet, undefined, {
connection: "google-oauth2"
});
expect(error?.code).toEqual("missing_refresh_token");
expect(federatedConnectionTokenSet).toBeNull();
});
});
});

const _authorizationServerMetadata = {
Expand Down Expand Up @@ -4449,4 +4224,4 @@ const _authorizationServerMetadata = {
backchannel_logout_session_supported: true,
end_session_endpoint: "https://guabu.us.auth0.com/oidc/logout",
pushed_authorization_request_endpoint: "https://guabu.us.auth0.com/oauth/par"
};
};
Loading
Loading