Overview
Theauthorize() method starts the Grantex authorization flow. It creates an authorization request and returns a consent URL where the user can approve or deny the requested scopes.
The
userId parameter is mapped to principalId in the API request body. This is the identifier for the human user in your system.Parameters
The ID of the agent requesting authorization (from
agents.register()).Your application’s user identifier. Mapped to
principalId in the protocol.The scopes the agent is requesting. Must be a subset of the agent’s registered scopes.
How long the grant should last (e.g.
'1h', '24h', '7d'). Defaults to the server-configured maximum.The URL to redirect the user to after they approve or deny the request. The authorization
code will be appended as a query parameter.Must be
'S256' when codeChallenge is provided.Response
The method returns anAuthorizationRequest object:
Unique identifier for this authorization request.
URL to redirect the user to for consent approval.
The agent that initiated the request.
The user identifier (mapped from
userId).The scopes requested in this authorization.
The requested grant duration.
ISO 8601 timestamp when the authorization request expires.
Current status:
'pending', 'approved', 'denied', or 'expired'.ISO 8601 timestamp when the request was created.
Full example
Next steps
After the user approves the request at theconsentUrl, your redirectUri receives an authorization code. Exchange it for a grant token using tokens.exchange().