mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-22 15:51:18 -07:00
feat(mcp): Add ODIC fallback to OAuth metadata look up (#6863)
Co-authored-by: cornmander <shikhman@google.com>
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user