OAuth2 Integration
Let users authorize your app to make X402 payments on their behalf
OAuth2 Integration
OAuth2 allows your application to request permission from AgnicPay users to make X402 payments on their behalf. Users set their own spending limits and can revoke access anytime.
Why OAuth2?
- User-controlled limits - Users set daily/monthly spending caps
- Revocable access - Users can disconnect your app anytime
- Network selection - Users choose which networks to allow
- Long-lived tokens - Access tokens last 30-60 days with refresh
Authorization Flow
Step 1: Redirect to Authorization
Redirect users to our authorization endpoint:
Step 2: User Grants Permission
The user logs in, sets spending limits (per-transaction, daily, monthly), selects allowed networks, and approves your app.
Step 3: Receive Authorization Code
User is redirected back to your app with an authorization code:
Step 4: Exchange for Tokens
Exchange the code for access and refresh tokens:
Token Response
Token Expiration:
- Access tokens: 30-60 days (varies by client type)
- Refresh tokens: 90 days
- N8N tokens: 1 year (for automation workflows)
Using the Access Token
Refreshing Tokens
When the access token expires, use the refresh token to get a new one:
Authorization Parameters
| Parameter | Required | Description |
|---|---|---|
client_id | Yes | Your application identifier |
redirect_uri | Yes | Where to send user after authorization |
state | Yes | CSRF protection token (returned unchanged) |
scope | No | Space-separated scopes (default: payments:sign balance:read) |
response_type | Yes | Must be code |
code_challenge | No | PKCE code challenge (recommended) |
code_challenge_method | No | PKCE method (default: S256) |
prompt | No | Controls consent behavior |
Prompt Parameter
The prompt parameter follows the OpenID Connect standard:
| Value | Behavior |
|---|---|
| (omitted) | Auto-approve if user previously consented |
none | Silent auth only - error if consent needed |
consent | Force consent screen even if previously consented |
login | Force re-authentication before authorization |
Returning users are auto-approved by default (like Google/GitHub). Use prompt=consent to force users to review permissions again.
Register Your Application
To use OAuth2, contact us to register your application and get your redirect URIs whitelisted.
PKCE (Recommended)
For public clients (mobile apps, SPAs), we recommend using PKCE: