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
string
required
The ID of the agent requesting authorization (from
agents.register()).string
required
Your application’s user identifier. Mapped to
principalId in the protocol.string[]
required
The scopes the agent is requesting. Must be a subset of the agent’s registered scopes.
string
Intended token recipient. When set, the issued grant token includes this value in its
aud claim; verifiers should require the same audience.string
How long the grant should last (e.g.
'1h', '24h', '7d'). Defaults to the server-configured maximum.string
The URL to redirect the user to after they approve or deny the request. The authorization
code will be appended as a query parameter.string
Must be
'S256' when codeChallenge is provided.Response
The method returns anAuthorizationRequest object:
string
Unique identifier for this authorization request.
string
URL to redirect the user to for consent approval.
string
The agent that initiated the request.
string
The user identifier (mapped from
userId).string[]
The scopes requested in this authorization.
string
The requested grant duration.
string
ISO 8601 timestamp when the authorization request expires.
string
Current status:
'pending', 'approved', 'denied', or 'expired'.string
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().