Skip to content

Commit c6947e2

Browse files
fix: Add id_token_hint on logout (#2041)
2 parents 5ba8896 + d09757d commit c6947e2

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/server/auth-client.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("Authentication Client", async () => {
1818
clientSecret: "client-secret",
1919
appBaseUrl: "https://example.com",
2020
sid: "auth0-sid",
21+
idToken: "idt_123",
2122
accessToken: "at_123",
2223
refreshToken: "rt_123",
2324
sub: "user_123",
@@ -1827,6 +1828,7 @@ ca/T0LLtgmbMmxSv/MmzIg==
18271828
const session: SessionData = {
18281829
user: { sub: DEFAULT.sub },
18291830
tokenSet: {
1831+
idToken: DEFAULT.idToken,
18301832
accessToken: DEFAULT.accessToken,
18311833
refreshToken: DEFAULT.refreshToken,
18321834
expiresAt: 123456
@@ -1864,6 +1866,9 @@ ca/T0LLtgmbMmxSv/MmzIg==
18641866
expect(authorizationUrl.searchParams.get("logout_hint")).toEqual(
18651867
DEFAULT.sid
18661868
);
1869+
expect(authorizationUrl.searchParams.get("id_token_hint")).toEqual(
1870+
DEFAULT.idToken
1871+
);
18671872

18681873
// session cookie is cleared
18691874
const cookie = response.cookies.get("__session");
@@ -1941,6 +1946,43 @@ ca/T0LLtgmbMmxSv/MmzIg==
19411946
expect(cookie?.expires).toEqual(new Date("1970-01-01T00:00:00.000Z"));
19421947
});
19431948

1949+
it("should not include the id_token_hint parameter if a session does not exist", async () => {
1950+
const secret = await generateSecret(32);
1951+
const transactionStore = new TransactionStore({
1952+
secret
1953+
});
1954+
const sessionStore = new StatelessSessionStore({
1955+
secret
1956+
});
1957+
const authClient = new AuthClient({
1958+
transactionStore,
1959+
sessionStore,
1960+
1961+
domain: DEFAULT.domain,
1962+
clientId: DEFAULT.clientId,
1963+
clientSecret: DEFAULT.clientSecret,
1964+
1965+
secret,
1966+
appBaseUrl: DEFAULT.appBaseUrl,
1967+
1968+
fetch: getMockAuthorizationServer()
1969+
});
1970+
1971+
const request = new NextRequest(
1972+
new URL("/auth/logout", DEFAULT.appBaseUrl),
1973+
{
1974+
method: "GET"
1975+
}
1976+
);
1977+
1978+
const response = await authClient.handleLogout(request);
1979+
expect(response.status).toEqual(307);
1980+
expect(response.headers.get("Location")).not.toBeNull();
1981+
1982+
const authorizationUrl = new URL(response.headers.get("Location")!);
1983+
expect(authorizationUrl.searchParams.get("id_token_hint")).toBeNull();
1984+
});
1985+
19441986
it("should not include the logout_hint parameter if a session does not exist", async () => {
19451987
const secret = await generateSecret(32);
19461988
const transactionStore = new TransactionStore({

src/server/auth-client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ export class AuthClient {
432432
url.searchParams.set("logout_hint", session.internal.sid);
433433
}
434434

435+
if (session?.tokenSet.idToken) {
436+
url.searchParams.set("id_token_hint", session?.tokenSet.idToken);
437+
}
438+
435439
const res = NextResponse.redirect(url);
436440
await this.sessionStore.delete(req.cookies, res.cookies);
437441

0 commit comments

Comments
 (0)