-
Notifications
You must be signed in to change notification settings - Fork 13k
feat(core): implement HTTP authentication support for A2A remote agents #20510
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20e3baf
feat(core): implement HTTP authentication support for A2A remote agents
SandyTao520 e15511f
feat(core): implement HTTP authentication support for A2A remote agents
SandyTao520 bd1ffa4
Merge remote-tracking branch 'origin/main' into st/feat/remote-agent-…
adamfweidman 4155ecd
refactor(a2a-server): cleanup authentication comments in customUserBu…
adamfweidman 73db8a9
fix(core): address PR review comments for HTTP auth
SandyTao520 38d2168
Merge branch 'st/feat/remote-agent-auth' of https://github.com/google…
SandyTao520 585957b
fix(core): remove ADC fallback entirely per review
SandyTao520 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
packages/core/src/agents/auth-provider/http-provider.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import { HttpAuthProvider } from './http-provider.js'; | ||
|
|
||
| describe('HttpAuthProvider', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('Bearer Authentication', () => { | ||
| it('should provide Bearer token header', async () => { | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'Bearer' as const, | ||
| token: 'test-token', | ||
| }; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| const headers = await provider.headers(); | ||
| expect(headers).toEqual({ Authorization: 'Bearer test-token' }); | ||
| }); | ||
|
|
||
| it('should resolve token from environment variable', async () => { | ||
| process.env['TEST_TOKEN'] = 'env-token'; | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'Bearer' as const, | ||
| token: '$TEST_TOKEN', | ||
| }; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| const headers = await provider.headers(); | ||
| expect(headers).toEqual({ Authorization: 'Bearer env-token' }); | ||
| delete process.env['TEST_TOKEN']; | ||
| }); | ||
| }); | ||
|
|
||
| describe('Basic Authentication', () => { | ||
| it('should provide Basic auth header', async () => { | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'Basic' as const, | ||
| username: 'user', | ||
| password: 'password', | ||
| }; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| const headers = await provider.headers(); | ||
| const expected = Buffer.from('user:password').toString('base64'); | ||
| expect(headers).toEqual({ Authorization: `Basic ${expected}` }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Generic/Raw Authentication', () => { | ||
| it('should provide custom scheme with raw value', async () => { | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'CustomScheme', | ||
| value: 'raw-value-here', | ||
| }; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| const headers = await provider.headers(); | ||
| expect(headers).toEqual({ Authorization: 'CustomScheme raw-value-here' }); | ||
| }); | ||
|
|
||
| it('should support Digest via raw value', async () => { | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'Digest', | ||
| value: 'username="foo", response="bar"', | ||
| }; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| const headers = await provider.headers(); | ||
| expect(headers).toEqual({ | ||
| Authorization: 'Digest username="foo", response="bar"', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Retry logic', () => { | ||
| it('should re-initialize on 401 for Bearer', async () => { | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'Bearer' as const, | ||
| token: '$DYNAMIC_TOKEN', | ||
| }; | ||
| process.env['DYNAMIC_TOKEN'] = 'first'; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| process.env['DYNAMIC_TOKEN'] = 'second'; | ||
| const mockResponse = { status: 401 } as Response; | ||
| const retryHeaders = await provider.shouldRetryWithHeaders( | ||
| {}, | ||
| mockResponse, | ||
| ); | ||
|
|
||
| expect(retryHeaders).toEqual({ Authorization: 'Bearer second' }); | ||
| delete process.env['DYNAMIC_TOKEN']; | ||
| }); | ||
|
|
||
| it('should stop after max retries', async () => { | ||
| const config = { | ||
| type: 'http' as const, | ||
| scheme: 'Bearer' as const, | ||
| token: 'token', | ||
| }; | ||
| const provider = new HttpAuthProvider(config); | ||
| await provider.initialize(); | ||
|
|
||
| const mockResponse = { status: 401 } as Response; | ||
|
|
||
| // MAX_AUTH_RETRIES is 2 | ||
| await provider.shouldRetryWithHeaders({}, mockResponse); | ||
| await provider.shouldRetryWithHeaders({}, mockResponse); | ||
| const third = await provider.shouldRetryWithHeaders({}, mockResponse); | ||
|
|
||
| expect(third).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.