-
Notifications
You must be signed in to change notification settings - Fork 651
Misc fixes in auth #157
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
Misc fixes in auth #157
Changes from 4 commits
1b8e94c
2dc7fa5
8a222e8
3b12961
aad2bad
26b4743
885590c
8dfa643
c521710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,11 +163,20 @@ export async function discoverOAuthMetadata( | |
opts?: { protocolVersion?: string }, | ||
): Promise<OAuthMetadata | undefined> { | ||
const url = new URL("/.well-known/oauth-authorization-server", serverUrl); | ||
const response = await fetch(url, { | ||
headers: { | ||
"MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION | ||
let response: Response; | ||
try { | ||
response = await fetch(url, { | ||
headers: { | ||
"MCP-Protocol-Version": opts?.protocolVersion ?? LATEST_PROTOCOL_VERSION | ||
} | ||
}); | ||
} catch { | ||
try { | ||
response = await fetch(url); | ||
} catch { | ||
return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure you don't want to log/throw the exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be fine to let this error propagate if there's an actual network error (or otherwise), rather than a 404. |
||
} | ||
}); | ||
} | ||
|
||
if (response.status === 404) { | ||
return undefined; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,10 +75,11 @@ export function clientRegistrationHandler({ | |
} | ||
|
||
const clientMetadata = parseResult.data; | ||
const isPublicClient = clientMetadata.token_endpoint_auth_method !== 'none' | ||
|
||
// Generate client credentials | ||
const clientId = crypto.randomUUID(); | ||
const clientSecret = clientMetadata.token_endpoint_auth_method !== 'none' | ||
const clientSecret = isPublicClient | ||
? crypto.randomBytes(32).toString('hex') | ||
: undefined; | ||
const clientIdIssuedAt = Math.floor(Date.now() / 1000); | ||
|
@@ -88,7 +89,11 @@ export function clientRegistrationHandler({ | |
client_id: clientId, | ||
client_secret: clientSecret, | ||
client_id_issued_at: clientIdIssuedAt, | ||
client_secret_expires_at: clientSecretExpirySeconds > 0 ? clientIdIssuedAt + clientSecretExpirySeconds : 0 | ||
client_secret_expires_at: isPublicClient | ||
? clientSecretExpirySeconds > 0 | ||
? clientIdIssuedAt + clientSecretExpirySeconds | ||
: 0 | ||
: undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nested ternaries is a bit much—can we pull some of this out into one or two intermediate variables? |
||
}; | ||
|
||
clientInfo = await clientsStore.registerClient!(clientInfo); | ||
|
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.
Do we want to conditionalize this based on what the error actually was?