Skip to content

Commit fd3665f

Browse files
committed
add test for selectClientAuthMethod
1 parent fb487a7 commit fd3665f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/client/auth.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
discoverOAuthProtectedResourceMetadata,
1111
extractResourceMetadataUrl,
1212
auth,
13-
type OAuthClientProvider
13+
type OAuthClientProvider,
14+
selectClientAuthMethod
1415
} from './auth.js';
1516
import { ServerError } from '../server/auth/errors.js';
1617
import { AuthorizationServerMetadata } from '../shared/auth.js';
@@ -881,6 +882,21 @@ describe('OAuth Authorization', () => {
881882
});
882883
});
883884

885+
describe('selectClientAuthMethod', () => {
886+
it('selects the correct client authentication method from client information', () => {
887+
const clientInfo = { client_id: 'test-client-id', client_secret: 'test-client-secret', token_endpoint_auth_method: 'client_secret_basic' };
888+
const supportedMethods = ['client_secret_post', 'client_secret_basic', 'none'];
889+
const authMethod = selectClientAuthMethod(clientInfo, supportedMethods);
890+
expect(authMethod).toBe('client_secret_basic');
891+
});
892+
it('selects the correct client authentication method from supported methods', () => {
893+
const clientInfo = { client_id: 'test-client-id' };
894+
const supportedMethods = ['client_secret_post', 'client_secret_basic', 'none'];
895+
const authMethod = selectClientAuthMethod(clientInfo, supportedMethods);
896+
expect(authMethod).toBe('none');
897+
});
898+
});
899+
884900
describe('startAuthorization', () => {
885901
const validMetadata = {
886902
issuer: 'https://auth.example.com',

src/client/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ const AUTHORIZATION_CODE_CHALLENGE_METHOD = 'S256';
169169
* @param supportedMethods - Authentication methods supported by the authorization server
170170
* @returns The selected authentication method
171171
*/
172-
function selectClientAuthMethod(clientInformation: OAuthClientInformationMixed, supportedMethods: string[]): ClientAuthMethod {
172+
export function selectClientAuthMethod(clientInformation: OAuthClientInformationMixed, supportedMethods: string[]): ClientAuthMethod {
173173
const hasClientSecret = clientInformation.client_secret !== undefined;
174174

175175
// If server doesn't specify supported methods, use RFC 6749 defaults

0 commit comments

Comments
 (0)