feat(mcp): Add ODIC fallback to OAuth metadata look up (#6863)

Co-authored-by: cornmander <shikhman@google.com>
This commit is contained in:
Amy He
2025-08-26 09:06:26 -07:00
committed by GitHub
parent e2b4b2ec7e
commit c9c905be1e
2 changed files with 146 additions and 62 deletions
+68
View File
@@ -142,6 +142,74 @@ describe('OAuthUtils', () => {
});
});
describe('discoverAuthorizationServerMetadata', () => {
const mockAuthServerMetadata: OAuthAuthorizationServerMetadata = {
issuer: 'https://auth.example.com',
authorization_endpoint: 'https://auth.example.com/authorize',
token_endpoint: 'https://auth.example.com/token',
scopes_supported: ['read', 'write'],
};
it('should handle URLs without path components correctly', async () => {
mockFetch
.mockResolvedValueOnce({
ok: false,
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(mockAuthServerMetadata),
});
const result = await OAuthUtils.discoverAuthorizationServerMetadata(
'https://auth.example.com/',
);
expect(result).toEqual(mockAuthServerMetadata);
expect(mockFetch).nthCalledWith(
1,
'https://auth.example.com/.well-known/oauth-authorization-server',
);
expect(mockFetch).nthCalledWith(
2,
'https://auth.example.com/.well-known/openid-configuration',
);
});
it('should handle URLs with path components correctly', async () => {
mockFetch
.mockResolvedValueOnce({
ok: false,
})
.mockResolvedValueOnce({
ok: false,
})
.mockResolvedValueOnce({
ok: true,
json: () => Promise.resolve(mockAuthServerMetadata),
});
const result = await OAuthUtils.discoverAuthorizationServerMetadata(
'https://auth.example.com/mcp',
);
expect(result).toEqual(mockAuthServerMetadata);
expect(mockFetch).nthCalledWith(
1,
'https://auth.example.com/.well-known/oauth-authorization-server/mcp',
);
expect(mockFetch).nthCalledWith(
2,
'https://auth.example.com/.well-known/openid-configuration/mcp',
);
expect(mockFetch).nthCalledWith(
3,
'https://auth.example.com/mcp/.well-known/openid-configuration',
);
});
});
describe('metadataToOAuthConfig', () => {
it('should convert metadata to OAuth config', () => {
const metadata: OAuthAuthorizationServerMetadata = {