-
Notifications
You must be signed in to change notification settings - Fork 15
Derive the end session endpoint from the server's logout path #43
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
madurangasiriwardena
merged 1 commit into
thunder-id:main
from
madurangasiriwardena:fix-default-end-session-endpoint
Jul 30, 2026
+119
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/javascript/src/__tests__/AuthenticationHelper.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** | ||
| * Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| * | ||
| * WSO2 LLC. licenses this file to you under the Apache License, | ||
| * Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import {describe, expect, it, beforeEach} from 'vitest'; | ||
| import type {IsomorphicCrypto} from '../IsomorphicCrypto'; | ||
| import type {AuthClientConfig} from '../models/config'; | ||
| import type {Storage} from '../models/store'; | ||
| import StorageManager from '../StorageManager'; | ||
| import AuthenticationHelper from '../utils/AuthenticationHelper'; | ||
|
|
||
| class MemoryStore implements Storage { | ||
| private store = new Map<string, string>(); | ||
|
|
||
| getData(key: string): Promise<string> { | ||
| return Promise.resolve(this.store.get(key) ?? null!); | ||
| } | ||
|
|
||
| setData(key: string, value: string): Promise<void> { | ||
| this.store.set(key, value); | ||
|
|
||
| return Promise.resolve(); | ||
| } | ||
|
|
||
| removeData(key: string): Promise<void> { | ||
| this.store.delete(key); | ||
|
|
||
| return Promise.resolve(); | ||
| } | ||
| } | ||
|
|
||
| const BASE_URL = 'https://localhost:8090'; | ||
|
|
||
| async function initHelper(config: Partial<AuthClientConfig<unknown>>): Promise<AuthenticationHelper<unknown>> { | ||
| const storageManager = new StorageManager<unknown>('test-instance', new MemoryStore()); | ||
| await storageManager.setConfigData(config); | ||
|
|
||
| return new AuthenticationHelper<unknown>(storageManager, {} as unknown as IsomorphicCrypto<unknown>); | ||
| } | ||
|
|
||
| describe('AuthenticationHelper', () => { | ||
| let helper: AuthenticationHelper<unknown>; | ||
|
|
||
| beforeEach(async () => { | ||
| helper = await initHelper({baseUrl: BASE_URL, clientId: 'test-client'}); | ||
| }); | ||
|
|
||
| describe('resolveEndpointsByBaseURL()', () => { | ||
| it('derives every endpoint under the base URL', async () => { | ||
| const endpoints = await helper.resolveEndpointsByBaseURL(); | ||
|
|
||
| expect(endpoints.authorization_endpoint).toBe(`${BASE_URL}/oauth2/authorize`); | ||
| expect(endpoints.token_endpoint).toBe(`${BASE_URL}/oauth2/token`); | ||
| expect(endpoints.jwks_uri).toBe(`${BASE_URL}/oauth2/jwks`); | ||
| expect(endpoints.revocation_endpoint).toBe(`${BASE_URL}/oauth2/revoke`); | ||
| expect(endpoints.userinfo_endpoint).toBe(`${BASE_URL}/oauth2/userinfo`); | ||
| expect(endpoints.issuer).toBe(BASE_URL); | ||
| }); | ||
|
|
||
| it('derives the end session endpoint on the path the server actually serves', async () => { | ||
| const endpoints = await helper.resolveEndpointsByBaseURL(); | ||
|
|
||
| expect(endpoints.end_session_endpoint).toBe(`${BASE_URL}/oauth2/logout`); | ||
| }); | ||
|
|
||
| it('lets explicitly configured endpoints override the derived defaults', async () => { | ||
| const configuredHelper = await initHelper({ | ||
| baseUrl: BASE_URL, | ||
| clientId: 'test-client', | ||
| endpoints: {endSessionEndpoint: 'https://idp.example.com/custom/logout'}, | ||
| }); | ||
|
|
||
| const endpoints = await configuredHelper.resolveEndpointsByBaseURL(); | ||
|
|
||
| expect(endpoints.end_session_endpoint).toBe('https://idp.example.com/custom/logout'); | ||
| expect(endpoints.token_endpoint).toBe(`${BASE_URL}/oauth2/token`); | ||
| }); | ||
|
|
||
| it('throws when no base URL is configured', async () => { | ||
| const helperWithoutBaseUrl = await initHelper({clientId: 'test-client'}); | ||
|
|
||
| await expect(helperWithoutBaseUrl.resolveEndpointsByBaseURL()).rejects.toMatchObject({ | ||
| code: 'JS-AUTH_HELPER_REBO-NF01', | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Do not promise a base-URL fallback when
baseUrlis absent.These warnings always say “falling back,” but the subsequent branches throw
JS-AUTH_CORE-GOPMD-HE01when nobaseUrlis configured. Make the message conditional or state that a fallback will be attempted only when available.Also applies to: 384-390
🤖 Prompt for AI Agents