Skip to content

Commit 9cccf91

Browse files
authored
Revert "Add support for Federated Connection Access Token (#1911)" (#1918)
2 parents caa7f45 + 748c965 commit 9cccf91

10 files changed

+81
-763
lines changed

examples/with-shadcn/middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextRequest } from "next/server"
33
import { auth0 } from "./lib/auth0"
44

55
export async function middleware(request: NextRequest) {
6-
return await auth0.middleware(request);
6+
return await auth0.middleware(request)
77
}
88

99
export const config = {

examples/with-shadcn/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"@auth0/nextjs-auth0": "^4.0.1",
12+
"@auth0/nextjs-auth0": "^4.0.0",
1313
"@radix-ui/react-avatar": "^1.1.1",
1414
"@radix-ui/react-collapsible": "^1.1.1",
1515
"@radix-ui/react-dialog": "^1.1.2",

examples/with-shadcn/pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/errors/index.ts

-43
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,3 @@ export class AccessTokenError extends SdkError {
9898
this.code = code;
9999
}
100100
}
101-
102-
/**
103-
* Enum representing error codes related to federated connection access tokens.
104-
*/
105-
export enum FederatedConnectionAccessTokenErrorCode {
106-
/**
107-
* The session is missing.
108-
*/
109-
MISSING_SESSION = "missing_session",
110-
111-
/**
112-
* The refresh token is missing.
113-
*/
114-
MISSING_REFRESH_TOKEN = "missing_refresh_token",
115-
116-
/**
117-
* Failed to exchange the refresh token.
118-
*/
119-
FAILED_TO_EXCHANGE = "failed_to_exchange_refresh_token"
120-
}
121-
122-
/**
123-
* Error class representing an access token error for federated connections.
124-
* Extends the `SdkError` class.
125-
*/
126-
export class FederatedConnectionsAccessTokenError extends SdkError {
127-
/**
128-
* The error code associated with the access token error.
129-
*/
130-
public code: string;
131-
132-
/**
133-
* Constructs a new `FederatedConnectionsAccessTokenError` instance.
134-
*
135-
* @param code - The error code.
136-
* @param message - The error message.
137-
*/
138-
constructor(code: string, message: string) {
139-
super(message);
140-
this.name = "FederatedConnectionAccessTokenError";
141-
this.code = code;
142-
}
143-
}

src/server/auth-client.test.ts

+1-226
Original file line numberDiff line numberDiff line change
@@ -4153,231 +4153,6 @@ ca/T0LLtgmbMmxSv/MmzIg==
41534153
});
41544154
});
41554155
});
4156-
4157-
describe("getFederatedConnectionTokenSet", async () => {
4158-
it("should call for an access token when no federated connection token set in the session", async () => {
4159-
const secret = await generateSecret(32);
4160-
const transactionStore = new TransactionStore({
4161-
secret
4162-
});
4163-
const sessionStore = new StatelessSessionStore({
4164-
secret
4165-
});
4166-
const fetchSpy = getMockAuthorizationServer({
4167-
tokenEndpointResponse: {
4168-
token_type: "Bearer",
4169-
access_token: DEFAULT.accessToken,
4170-
expires_in: 86400 // expires in 10 days
4171-
} as oauth.TokenEndpointResponse
4172-
});
4173-
4174-
const authClient = new AuthClient({
4175-
transactionStore,
4176-
sessionStore,
4177-
4178-
domain: DEFAULT.domain,
4179-
clientId: DEFAULT.clientId,
4180-
clientSecret: DEFAULT.clientSecret,
4181-
4182-
secret,
4183-
appBaseUrl: DEFAULT.appBaseUrl,
4184-
4185-
fetch: fetchSpy
4186-
});
4187-
4188-
const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
4189-
const tokenSet = {
4190-
accessToken: DEFAULT.accessToken,
4191-
refreshToken: DEFAULT.refreshToken,
4192-
expiresAt
4193-
};
4194-
4195-
const response = await authClient.getFederatedConnectionTokenSet(
4196-
tokenSet,
4197-
undefined,
4198-
{ connection: "google-oauth2", login_hint: "000100123" }
4199-
);
4200-
const [error, federatedConnectionTokenSet] = response;
4201-
expect(error).toBe(null);
4202-
expect(fetchSpy).toHaveBeenCalled();
4203-
expect(federatedConnectionTokenSet).toEqual({
4204-
accessToken: DEFAULT.accessToken,
4205-
connection: "google-oauth2",
4206-
expiresAt: expect.any(Number)
4207-
});
4208-
});
4209-
4210-
it("should return access token from the session when federated connection token set in the session is not expired", async () => {
4211-
const secret = await generateSecret(32);
4212-
const transactionStore = new TransactionStore({
4213-
secret
4214-
});
4215-
const sessionStore = new StatelessSessionStore({
4216-
secret
4217-
});
4218-
const fetchSpy = vi.fn();
4219-
const authClient = new AuthClient({
4220-
transactionStore,
4221-
sessionStore,
4222-
4223-
domain: DEFAULT.domain,
4224-
clientId: DEFAULT.clientId,
4225-
clientSecret: DEFAULT.clientSecret,
4226-
4227-
secret,
4228-
appBaseUrl: DEFAULT.appBaseUrl,
4229-
4230-
fetch: fetchSpy
4231-
});
4232-
4233-
const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
4234-
const tokenSet = {
4235-
accessToken: DEFAULT.accessToken,
4236-
refreshToken: DEFAULT.refreshToken,
4237-
expiresAt,
4238-
};
4239-
4240-
const response = await authClient.getFederatedConnectionTokenSet(
4241-
tokenSet,
4242-
{ connection: 'google-oauth2', accessToken: 'fc_at', expiresAt: Math.floor(Date.now() / 1000) + 86400 },
4243-
{ connection: "google-oauth2", login_hint: "000100123" }
4244-
);
4245-
const [error, federatedConnectionTokenSet] = response;
4246-
expect(error).toBe(null);
4247-
expect(federatedConnectionTokenSet).toEqual({
4248-
accessToken: 'fc_at',
4249-
connection: "google-oauth2",
4250-
expiresAt: expect.any(Number)
4251-
});
4252-
expect(fetchSpy).not.toHaveBeenCalled();
4253-
});
4254-
4255-
it("should call for an access token when federated connection token set in the session is expired", async () => {
4256-
const secret = await generateSecret(32);
4257-
const transactionStore = new TransactionStore({
4258-
secret
4259-
});
4260-
const sessionStore = new StatelessSessionStore({
4261-
secret
4262-
});
4263-
const fetchSpy = getMockAuthorizationServer({
4264-
tokenEndpointResponse: {
4265-
token_type: "Bearer",
4266-
access_token: DEFAULT.accessToken,
4267-
expires_in: 86400 // expires in 10 days
4268-
} as oauth.TokenEndpointResponse
4269-
});
4270-
const authClient = new AuthClient({
4271-
transactionStore,
4272-
sessionStore,
4273-
4274-
domain: DEFAULT.domain,
4275-
clientId: DEFAULT.clientId,
4276-
clientSecret: DEFAULT.clientSecret,
4277-
4278-
secret,
4279-
appBaseUrl: DEFAULT.appBaseUrl,
4280-
4281-
fetch: fetchSpy
4282-
});
4283-
4284-
const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
4285-
const tokenSet = {
4286-
accessToken: DEFAULT.accessToken,
4287-
refreshToken: DEFAULT.refreshToken,
4288-
expiresAt,
4289-
};
4290-
4291-
const response = await authClient.getFederatedConnectionTokenSet(
4292-
tokenSet,
4293-
{ connection: 'google-oauth2', accessToken: 'fc_at', expiresAt },
4294-
{ connection: "google-oauth2", login_hint: "000100123" }
4295-
);
4296-
const [error, federatedConnectionTokenSet] = response;
4297-
expect(error).toBe(null);
4298-
expect(federatedConnectionTokenSet).toEqual({
4299-
accessToken: DEFAULT.accessToken,
4300-
connection: "google-oauth2",
4301-
expiresAt: expect.any(Number)
4302-
});
4303-
expect(fetchSpy).toHaveBeenCalled();
4304-
});
4305-
4306-
it("should return an error if the discovery endpoint could not be fetched", async () => {
4307-
const secret = await generateSecret(32);
4308-
const transactionStore = new TransactionStore({
4309-
secret
4310-
});
4311-
const sessionStore = new StatelessSessionStore({
4312-
secret
4313-
});
4314-
const authClient = new AuthClient({
4315-
transactionStore,
4316-
sessionStore,
4317-
4318-
domain: DEFAULT.domain,
4319-
clientId: DEFAULT.clientId,
4320-
clientSecret: DEFAULT.clientSecret,
4321-
4322-
secret,
4323-
appBaseUrl: DEFAULT.appBaseUrl,
4324-
4325-
fetch: getMockAuthorizationServer({
4326-
discoveryResponse: new Response(null, { status: 500 })
4327-
})
4328-
});
4329-
4330-
const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
4331-
const tokenSet = {
4332-
accessToken: DEFAULT.accessToken,
4333-
refreshToken: DEFAULT.refreshToken,
4334-
expiresAt
4335-
};
4336-
4337-
const [error, federatedConnectionTokenSet] =
4338-
await authClient.getFederatedConnectionTokenSet(tokenSet, undefined, {
4339-
connection: "google-oauth2"
4340-
});
4341-
expect(error?.code).toEqual("discovery_error");
4342-
expect(federatedConnectionTokenSet).toBeNull();
4343-
});
4344-
4345-
it("should return an error if the token set does not contain a refresh token", async () => {
4346-
const secret = await generateSecret(32);
4347-
const transactionStore = new TransactionStore({
4348-
secret
4349-
});
4350-
const sessionStore = new StatelessSessionStore({
4351-
secret
4352-
});
4353-
const authClient = new AuthClient({
4354-
transactionStore,
4355-
sessionStore,
4356-
4357-
domain: DEFAULT.domain,
4358-
clientId: DEFAULT.clientId,
4359-
clientSecret: DEFAULT.clientSecret,
4360-
4361-
secret,
4362-
appBaseUrl: DEFAULT.appBaseUrl,
4363-
4364-
fetch: getMockAuthorizationServer()
4365-
});
4366-
4367-
const expiresAt = Math.floor(Date.now() / 1000) - 10 * 24 * 60 * 60; // expired 10 days ago
4368-
const tokenSet = {
4369-
accessToken: DEFAULT.accessToken,
4370-
expiresAt
4371-
};
4372-
4373-
const [error, federatedConnectionTokenSet] =
4374-
await authClient.getFederatedConnectionTokenSet(tokenSet, undefined, {
4375-
connection: "google-oauth2"
4376-
});
4377-
expect(error?.code).toEqual("missing_refresh_token");
4378-
expect(federatedConnectionTokenSet).toBeNull();
4379-
});
4380-
});
43814156
});
43824157

43834158
const _authorizationServerMetadata = {
@@ -4449,4 +4224,4 @@ const _authorizationServerMetadata = {
44494224
backchannel_logout_session_supported: true,
44504225
end_session_endpoint: "https://guabu.us.auth0.com/oidc/logout",
44514226
pushed_authorization_request_endpoint: "https://guabu.us.auth0.com/oauth/par"
4452-
};
4227+
};

0 commit comments

Comments
 (0)