使用说明:填写你在「应用管理」中注册的应用凭证,按照步骤完成测试。本页面本身可作为回调地址使用(需先在应用管理中配置 http://localhost:3000/auth-test.html)。

⚙ 应用配置

在「应用管理」中注册应用后获得的 App ID
注册应用时显示的 Secret,仅展示一次,请妥善保存
必须与「应用管理」中配置的回调地址一致。建议填写本页面地址用于测试:http://localhost:3000/auth-test.html
多个权限用英文逗号分隔:basic(默认)、email、profile

🔄 授权流程

1
构造授权链接
引导用户跳转到 OneAuth 授权页面

点击下方按钮或链接,将用户浏览器重定向到 OneAuth 授权页。用户登录并确认授权后,会带着 code 返回到你设置的回调地址。

请先在上方填写应用配置,然后点击「生成授权链接」
2
获取授权码
从回调 URL 中提取 code 参数

用户授权成功后,OneAuth 会将浏览器重定向回回调地址,URL 中附带授权码:

https://your-site.com/callback?code=xxxxxxxxxxxxxxxx
等待授权回调...
3
换取 Access Token
使用 code + AppSecret 调用服务端接口

在你的服务端后台,使用授权码、AppID 和 AppSecret 向 OneAuth 申请 Access Token:

POST /api/auth/exchange Content-Type: application/json { "appId": "your_app_id", "appSecret": "your_app_secret", "code": "code_from_step_2" }
4
获取用户信息
使用 Access Token 请求用户数据

拿到 Access Token 后,就可以获取授权用户的信息了:

GET /api/auth/userinfo Authorization: Bearer <access_token>

📈 流程时序图

你的应用 OneAuth 平台 用户浏览器 | | | | 1. 构造授权链接 | | |----------------------------> | | | 2. 跳转授权页面 | | |---------------------------->| | | 3. 登录并确认授权 | | |<----------------------------| | | 4. 重定向回回调地址 + code | | |---------------------------->| | 5. 接收 code | | |<---------------------------| | | 6. POST /exchange | | |---------------------------->| | | 7. 返回 access_token | | |<----------------------------| | | 8. GET /userinfo | | |---------------------------->| | | 9. 返回用户数据 | | |<----------------------------| |