Skip to content

Commit 9bda5df

Browse files
committed
apply OAuthClientInformationMixed type
1 parent 065d235 commit 9bda5df

File tree

6 files changed

+28
-37
lines changed

6 files changed

+28
-37
lines changed

src/client/auth.test.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,7 @@ describe('OAuth Authorization', () => {
15881588
// Mock provider methods for authorization flow
15891589
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
15901590
client_id: 'test-client',
1591-
client_secret: 'test-secret',
1592-
redirect_uris: ['http://localhost:3000/callback']
1591+
client_secret: 'test-secret'
15931592
});
15941593
(mockProvider.tokens as jest.Mock).mockResolvedValue(undefined);
15951594
(mockProvider.saveCodeVerifier as jest.Mock).mockResolvedValue(undefined);
@@ -1659,8 +1658,7 @@ describe('OAuth Authorization', () => {
16591658
// Mock provider methods for token exchange
16601659
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
16611660
client_id: 'test-client',
1662-
client_secret: 'test-secret',
1663-
redirect_uris: ['http://localhost:3000/callback']
1661+
client_secret: 'test-secret'
16641662
});
16651663
(mockProvider.codeVerifier as jest.Mock).mockResolvedValue('test-verifier');
16661664
(mockProvider.saveTokens as jest.Mock).mockResolvedValue(undefined);
@@ -1726,8 +1724,7 @@ describe('OAuth Authorization', () => {
17261724
// Mock provider methods for token refresh
17271725
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
17281726
client_id: 'test-client',
1729-
client_secret: 'test-secret',
1730-
redirect_uris: ['http://localhost:3000/callback']
1727+
client_secret: 'test-secret'
17311728
});
17321729
(mockProvider.tokens as jest.Mock).mockResolvedValue({
17331730
access_token: 'old-access',
@@ -1793,8 +1790,7 @@ describe('OAuth Authorization', () => {
17931790
// Mock provider methods
17941791
(providerWithCustomValidation.clientInformation as jest.Mock).mockResolvedValue({
17951792
client_id: 'test-client',
1796-
client_secret: 'test-secret',
1797-
redirect_uris: ['http://localhost:3000/callback']
1793+
client_secret: 'test-secret'
17981794
});
17991795
(providerWithCustomValidation.tokens as jest.Mock).mockResolvedValue(undefined);
18001796
(providerWithCustomValidation.saveCodeVerifier as jest.Mock).mockResolvedValue(undefined);
@@ -1849,8 +1845,7 @@ describe('OAuth Authorization', () => {
18491845
// Mock provider methods
18501846
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
18511847
client_id: 'test-client',
1852-
client_secret: 'test-secret',
1853-
redirect_uris: ['http://localhost:3000/callback']
1848+
client_secret: 'test-secret'
18541849
});
18551850
(mockProvider.tokens as jest.Mock).mockResolvedValue(undefined);
18561851
(mockProvider.saveCodeVerifier as jest.Mock).mockResolvedValue(undefined);
@@ -1908,8 +1903,7 @@ describe('OAuth Authorization', () => {
19081903
// Mock provider methods
19091904
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
19101905
client_id: 'test-client',
1911-
client_secret: 'test-secret',
1912-
redirect_uris: ['http://localhost:3000/callback']
1906+
client_secret: 'test-secret'
19131907
});
19141908
(mockProvider.tokens as jest.Mock).mockResolvedValue(undefined);
19151909
(mockProvider.saveCodeVerifier as jest.Mock).mockResolvedValue(undefined);
@@ -1976,8 +1970,7 @@ describe('OAuth Authorization', () => {
19761970
// Mock provider methods for token exchange
19771971
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
19781972
client_id: 'test-client',
1979-
client_secret: 'test-secret',
1980-
redirect_uris: ['http://localhost:3000/callback']
1973+
client_secret: 'test-secret'
19811974
});
19821975
(mockProvider.codeVerifier as jest.Mock).mockResolvedValue('test-verifier');
19831976
(mockProvider.saveTokens as jest.Mock).mockResolvedValue(undefined);
@@ -2040,8 +2033,7 @@ describe('OAuth Authorization', () => {
20402033
// Mock provider methods for token refresh
20412034
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
20422035
client_id: 'test-client',
2043-
client_secret: 'test-secret',
2044-
redirect_uris: ['http://localhost:3000/callback']
2036+
client_secret: 'test-secret'
20452037
});
20462038
(mockProvider.tokens as jest.Mock).mockResolvedValue({
20472039
access_token: 'old-access',
@@ -2102,8 +2094,7 @@ describe('OAuth Authorization', () => {
21022094
// Mock provider methods
21032095
(mockProvider.clientInformation as jest.Mock).mockResolvedValue({
21042096
client_id: 'test-client',
2105-
client_secret: 'test-secret',
2106-
redirect_uris: ['http://localhost:3000/callback']
2097+
client_secret: 'test-secret'
21072098
});
21082099
(mockProvider.tokens as jest.Mock).mockResolvedValue(undefined);
21092100
(mockProvider.saveCodeVerifier as jest.Mock).mockResolvedValue(undefined);
@@ -2165,8 +2156,7 @@ describe('OAuth Authorization', () => {
21652156
},
21662157
clientInformation: jest.fn().mockResolvedValue({
21672158
client_id: 'client123',
2168-
client_secret: 'secret123',
2169-
redirect_uris: ['http://localhost:3000/callback']
2159+
client_secret: 'secret123'
21702160
}),
21712161
tokens: jest.fn().mockResolvedValue(undefined),
21722162
saveTokens: jest.fn(),

src/client/auth.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import pkceChallenge from 'pkce-challenge';
22
import { LATEST_PROTOCOL_VERSION } from '../types.js';
33
import {
44
OAuthClientMetadata,
5+
OAuthClientInformation,
6+
OAuthClientInformationMixed,
57
OAuthTokens,
68
OAuthMetadata,
79
OAuthClientInformationFull,
@@ -55,7 +57,7 @@ export interface OAuthClientProvider {
5557
* server, or returns `undefined` if the client is not registered with the
5658
* server.
5759
*/
58-
clientInformation(): OAuthClientInformationFull | undefined | Promise<OAuthClientInformationFull | undefined>;
60+
clientInformation(): OAuthClientInformationMixed | undefined | Promise<OAuthClientInformationMixed | undefined>;
5961

6062
/**
6163
* If implemented, this permits the OAuth client to dynamically register with
@@ -65,7 +67,7 @@ export interface OAuthClientProvider {
6567
* This method is not required to be implemented if client information is
6668
* statically known (e.g., pre-registered).
6769
*/
68-
saveClientInformation?(clientInformation: OAuthClientInformationFull): void | Promise<void>;
70+
saveClientInformation?(clientInformation: OAuthClientInformationMixed): void | Promise<void>;
6971

7072
/**
7173
* Loads any existing OAuth tokens for the current session, or returns
@@ -167,7 +169,7 @@ const AUTHORIZATION_CODE_CHALLENGE_METHOD = 'S256';
167169
* @param supportedMethods - Authentication methods supported by the authorization server
168170
* @returns The selected authentication method
169171
*/
170-
function selectClientAuthMethod(clientInformation: OAuthClientInformationFull, supportedMethods: string[]): ClientAuthMethod {
172+
function selectClientAuthMethod(clientInformation: OAuthClientInformationMixed, supportedMethods: string[]): ClientAuthMethod {
171173
const hasClientSecret = clientInformation.client_secret !== undefined;
172174

173175
// If server doesn't specify supported methods, use RFC 6749 defaults
@@ -177,6 +179,7 @@ function selectClientAuthMethod(clientInformation: OAuthClientInformationFull, s
177179

178180
// Prefer the method returned by the server during client registration if valid and supported
179181
if (
182+
'token_endpoint_auth_method' in clientInformation &&
180183
clientInformation.token_endpoint_auth_method &&
181184
isClientAuthMethod(clientInformation.token_endpoint_auth_method) &&
182185
supportedMethods.includes(clientInformation.token_endpoint_auth_method)
@@ -217,7 +220,7 @@ function selectClientAuthMethod(clientInformation: OAuthClientInformationFull, s
217220
*/
218221
function applyClientAuthentication(
219222
method: ClientAuthMethod,
220-
clientInformation: OAuthClientInformationFull,
223+
clientInformation: OAuthClientInformation,
221224
headers: Headers,
222225
params: URLSearchParams
223226
): void {
@@ -805,7 +808,7 @@ export async function startAuthorization(
805808
resource
806809
}: {
807810
metadata?: AuthorizationServerMetadata;
808-
clientInformation: OAuthClientInformationFull;
811+
clientInformation: OAuthClientInformationMixed;
809812
redirectUrl: string | URL;
810813
scope?: string;
811814
state?: string;
@@ -888,7 +891,7 @@ export async function exchangeAuthorization(
888891
fetchFn
889892
}: {
890893
metadata?: AuthorizationServerMetadata;
891-
clientInformation: OAuthClientInformationFull;
894+
clientInformation: OAuthClientInformationMixed;
892895
authorizationCode: string;
893896
codeVerifier: string;
894897
redirectUri: string | URL;
@@ -967,7 +970,7 @@ export async function refreshAuthorization(
967970
fetchFn
968971
}: {
969972
metadata?: AuthorizationServerMetadata;
970-
clientInformation: OAuthClientInformationFull;
973+
clientInformation: OAuthClientInformationMixed;
971974
refreshToken: string;
972975
resource?: URL;
973976
addClientAuthentication?: OAuthClientProvider['addClientAuthentication'];

src/client/sse.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,7 @@ describe('SSEClientTransport', () => {
357357
},
358358
clientInformation: jest.fn(() => ({
359359
client_id: 'test-client-id',
360-
client_secret: 'test-client-secret',
361-
redirect_uris: ['http://localhost/callback']
360+
client_secret: 'test-client-secret'
362361
})),
363362
tokens: jest.fn(),
364363
saveTokens: jest.fn(),
@@ -1163,8 +1162,7 @@ describe('SSEClientTransport', () => {
11631162
const clientInfo = config.clientRegistered
11641163
? {
11651164
client_id: 'test-client-id',
1166-
client_secret: 'test-client-secret',
1167-
redirect_uris: ['http://localhost/callback']
1165+
client_secret: 'test-client-secret'
11681166
}
11691167
: undefined;
11701168

src/client/streamableHttp.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ describe('StreamableHTTPClientTransport', () => {
1717
},
1818
clientInformation: jest.fn(() => ({
1919
client_id: 'test-client-id',
20-
client_secret: 'test-client-secret',
21-
redirect_uris: ['http://localhost/callback']
20+
client_secret: 'test-client-secret'
2221
})),
2322
tokens: jest.fn(),
2423
saveTokens: jest.fn(),

src/examples/client/simpleOAuthClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { URL } from 'node:url';
66
import { exec } from 'node:child_process';
77
import { Client } from '../../client/index.js';
88
import { StreamableHTTPClientTransport } from '../../client/streamableHttp.js';
9-
import { OAuthClientInformationFull, OAuthClientMetadata, OAuthTokens } from '../../shared/auth.js';
9+
import { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from '../../shared/auth.js';
1010
import { CallToolRequest, ListToolsRequest, CallToolResultSchema, ListToolsResultSchema } from '../../types.js';
1111
import { OAuthClientProvider, UnauthorizedError } from '../../client/auth.js';
1212

@@ -20,7 +20,7 @@ const CALLBACK_URL = `http://localhost:${CALLBACK_PORT}/callback`;
2020
* In production, you should persist tokens securely
2121
*/
2222
class InMemoryOAuthClientProvider implements OAuthClientProvider {
23-
private _clientInformation?: OAuthClientInformationFull;
23+
private _clientInformation?: OAuthClientInformationMixed;
2424
private _tokens?: OAuthTokens;
2525
private _codeVerifier?: string;
2626

@@ -46,11 +46,11 @@ class InMemoryOAuthClientProvider implements OAuthClientProvider {
4646
return this._clientMetadata;
4747
}
4848

49-
clientInformation(): OAuthClientInformationFull | undefined {
49+
clientInformation(): OAuthClientInformationMixed | undefined {
5050
return this._clientInformation;
5151
}
5252

53-
saveClientInformation(clientInformation: OAuthClientInformationFull): void {
53+
saveClientInformation(clientInformation: OAuthClientInformationMixed): void {
5454
this._clientInformation = clientInformation;
5555
}
5656

src/shared/auth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export type OAuthErrorResponse = z.infer<typeof OAuthErrorResponseSchema>;
226226
export type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
227227
export type OAuthClientInformation = z.infer<typeof OAuthClientInformationSchema>;
228228
export type OAuthClientInformationFull = z.infer<typeof OAuthClientInformationFullSchema>;
229+
export type OAuthClientInformationMixed = OAuthClientInformation | OAuthClientInformationFull;
229230
export type OAuthClientRegistrationError = z.infer<typeof OAuthClientRegistrationErrorSchema>;
230231
export type OAuthTokenRevocationRequest = z.infer<typeof OAuthTokenRevocationRequestSchema>;
231232
export type OAuthProtectedResourceMetadata = z.infer<typeof OAuthProtectedResourceMetadataSchema>;

0 commit comments

Comments
 (0)