Skip to content

Commit a0069e2

Browse files
committed
Split full/partial client information
1 parent afae421 commit a0069e2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/client/auth.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pkceChallenge from "pkce-challenge";
22
import { LATEST_PROTOCOL_VERSION } from "../types.js";
3-
import type { OAuthClientMetadata, OAuthClientInformation, OAuthTokens, OAuthMetadata } from "../shared/auth.js";
4-
import { OAuthClientInformationSchema, OAuthMetadataSchema, OAuthTokensSchema } from "../shared/auth.js";
3+
import type { OAuthClientMetadata, OAuthClientInformation, OAuthTokens, OAuthMetadata, OAuthClientInformationFull } from "../shared/auth.js";
4+
import { OAuthClientInformationFullSchema, OAuthMetadataSchema, OAuthTokensSchema } from "../shared/auth.js";
55

66
/**
77
* Implements an end-to-end OAuth client to be used with one MCP server.
@@ -36,7 +36,7 @@ export interface OAuthClientProvider {
3636
* This method is not required to be implemented if client information is
3737
* statically known (e.g., pre-registered).
3838
*/
39-
saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
39+
saveClientInformation?(clientInformation: OAuthClientInformationFull): void | Promise<void>;
4040

4141
/**
4242
* Loads any existing OAuth tokens for the current session, or returns
@@ -98,12 +98,13 @@ export async function auth(
9898
throw new Error("OAuth client information must be saveable for dynamic registration");
9999
}
100100

101-
clientInformation = await registerClient(serverUrl, {
101+
const fullInformation = await registerClient(serverUrl, {
102102
metadata,
103103
clientMetadata: provider.clientMetadata,
104104
});
105105

106-
await provider.saveClientInformation(clientInformation);
106+
await provider.saveClientInformation(fullInformation);
107+
clientInformation = fullInformation;
107108
}
108109

109110
// Exchange authorization code for tokens
@@ -371,7 +372,7 @@ export async function registerClient(
371372
metadata?: OAuthMetadata;
372373
clientMetadata: OAuthClientMetadata;
373374
},
374-
): Promise<OAuthClientInformation> {
375+
): Promise<OAuthClientInformationFull> {
375376
let registrationUrl: URL;
376377

377378
if (metadata) {
@@ -396,5 +397,5 @@ export async function registerClient(
396397
throw new Error(`Dynamic client registration failed: HTTP ${response.status}`);
397398
}
398399

399-
return OAuthClientInformationSchema.parse(await response.json());
400+
return OAuthClientInformationFullSchema.parse(await response.json());
400401
}

src/shared/auth.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ export const OAuthClientMetadataSchema = z.object({
7979
}).passthrough();
8080

8181
/**
82-
* RFC 7591 OAuth 2.0 Dynamic Client Registration response
82+
* RFC 7591 OAuth 2.0 Dynamic Client Registration client information
8383
*/
84-
export const OAuthClientInformationSchema = OAuthClientMetadataSchema.extend({
84+
export const OAuthClientInformationSchema = z.object({
8585
client_id: z.string(),
8686
client_secret: z.string().optional(),
8787
client_id_issued_at: z.number().optional(),
8888
client_secret_expires_at: z.number().optional(),
8989
}).passthrough();
9090

91+
/**
92+
* RFC 7591 OAuth 2.0 Dynamic Client Registration full response (client information plus metadata)
93+
*/
94+
export const OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
95+
9196
/**
9297
* RFC 7591 OAuth 2.0 Dynamic Client Registration error response
9398
*/
@@ -101,4 +106,5 @@ export type OAuthTokens = z.infer<typeof OAuthTokensSchema>;
101106
export type OAuthError = z.infer<typeof OAuthErrorSchema>;
102107
export type OAuthClientMetadata = z.infer<typeof OAuthClientMetadataSchema>;
103108
export type OAuthClientInformation = z.infer<typeof OAuthClientInformationSchema>;
109+
export type OAuthClientInformationFull = z.infer<typeof OAuthClientInformationFullSchema>;
104110
export type OAuthClientRegistrationError = z.infer<typeof OAuthClientRegistrationErrorSchema>;

0 commit comments

Comments
 (0)