App Integration OAuth Tutorial: Authorization Code Flow with PKCE
2026-11-23 · 原创·功能教程
Understand the goal
App integration lets users authorize your application before it acts on their behalf. This tutorial is for developers who need authorization, tiered calls, and app-scoped usage. For developers new to AI platforms, the flow can be understood in three parts: the user grants consent, your app receives the relevant permissions, and the app makes calls and checks app-scoped usage within those permissions. Start by reading /docs#docs-oauth. Confirm whether your application is a public client; public clients must use S256.
Prepare the minimum scopes
Before implementation, list the capabilities your business actually needs and request only the minimum scopes required. Do not request every available permission just to simplify development. Pay particular attention to permission boundaries: balance and usage scopes are separate. If your application does not need to check balance, do not request the balance scope. Usage checks should remain scoped to your own application.
Use the authorization code flow with PKCE
Follow the documentation and use the OAuth authorization code flow with PKCE. Public clients must use S256. Initiate the authorization request as described in the documentation and guide the user through consent. After the user authorizes the application, proceed to the token exchange step defined by the flow. At this stage, remember the security rule: never expose ext tokens in browser code, and do not let frontend code access the token.
Check results under granted permissions
After authorization, the application should operate only within the scopes the user approved. If you need to display balance or usage, verify the corresponding permission separately. Balance and usage scopes are separate and cannot substitute for each other. When reviewing usage, treat it as app-scoped usage for your application, not data from another application. If a permission is missing, revisit your scope design instead of assuming that authorization automatically includes additional capabilities.
Safety checklist
Keep these points in your implementation review:
- Request only the minimum scopes required by the business.
- Public clients must use S256.
- Never place ext tokens in browser frontend code.
- Request and check balance and usage permissions separately.
During development, review where the authorization request is created, where the token is handled, and which scopes are requested. The goal is to avoid exposing unnecessary information to the frontend and to keep authorization aligned with the application’s actual needs.
Once these steps are complete, use /docs#docs-oauth to cross-check your integration flow. You can then continue according to your business needs with the platform’s corresponding tools.