Documentation
¶
Overview ¶
Package credentials lets an agent obtain a user's access to a third-party API in the middle of a task, the case A2A models as TASK_STATE_AUTH_REQUIRED (spec 7.6), without the agent ever holding the user's raw token.
The flow is:
- Lookup: does the user already have a connection for the integration?
- If not, Begin returns a Challenge with a link. The agent puts the task into AUTH_REQUIRED and sends the link with NewChallengeParts.
- Await blocks until the user completes the flow at the broker. Spec 7.6.1 lets the agent continue on its own at that point, without a follow-up message.
- The agent calls the provider's API through Grant.Call. The broker adds the credential, so the token never travels through the chain of A2A agents (spec 7.6.3).
Implementations: credentials/demo (a fake consent page, no accounts needed) and credentials/nango (Nango Connect, then API calls through the Nango proxy).
Index ¶
Constants ¶
const MetadataKey = "https://threeagents.dev/ext/credential-challenge/v1"
MetadataKey marks the data part that carries a Challenge in an AUTH_REQUIRED status message. It lets a client or console show a "connect" button instead of parsing text.
Variables ¶
var ( // ErrNoGrant means the user has no usable connection for the integration. ErrNoGrant = errors.New("credentials: no grant for this user and integration") // ErrDenied means the user declined the request. ErrDenied = errors.New("credentials: the user denied access") // ErrExpired means the challenge expired before the user completed it. ErrExpired = errors.New("credentials: the challenge expired") )
Functions ¶
Types ¶
type Broker ¶
type Broker interface {
// Lookup returns the user's existing grant for the integration, or ErrNoGrant.
Lookup(ctx context.Context, user, integration string) (Grant, error)
// Begin starts a new authorization flow and returns the link to send to the user.
Begin(ctx context.Context, user, integration string) (*Challenge, error)
// Await blocks until the challenge is completed, denied, expired or ctx is done.
Await(ctx context.Context, challenge *Challenge) (Grant, error)
}
Broker obtains and uses user credentials on an agent's behalf.
type Challenge ¶
type Challenge struct {
// ID is the broker's identifier for this flow.
ID string `json:"id"`
User string `json:"user"`
Integration string `json:"integration"`
URL string `json:"url"`
ExpiresAt time.Time `json:"expiresAt"`
}
Challenge is an authorization flow waiting for the user.
type Grant ¶
type Grant interface {
// ConnectionID identifies the connection at the broker.
ConnectionID() string
// Call sends a request to a path of the provider's API, for example
// "/calendar/v3/calendars/primary/events", with body encoded as JSON. When out is
// non-nil, the JSON response is decoded into it.
Call(ctx context.Context, method, path string, body, out any) error
}
Grant is a connection the user approved.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package demo is a credentials.Broker that needs no accounts: its consent page is a local web page, and the only provider API it fakes is Google Calendar event creation.
|
Package demo is a credentials.Broker that needs no accounts: its consent page is a local web page, and the only provider API it fakes is Google Calendar event creation. |
|
Package nango is a credentials.Broker backed by Nango (https://nango.dev).
|
Package nango is a credentials.Broker backed by Nango (https://nango.dev). |