mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-19 14:31:56 +08:00
取消错误更改
This commit is contained in:
parent
0da3da33ef
commit
cd24fe93b7
52
README.md
52
README.md
@ -28,6 +28,58 @@ Q58论坛网址: https://q58.club
|
|||||||
2. 未登录本系统, 未登录q58论坛, 检查: 用户在接入应用中登录, 然后登录本系统, 然后登录q58论坛, 正常一直回调到用户应用
|
2. 未登录本系统, 未登录q58论坛, 检查: 用户在接入应用中登录, 然后登录本系统, 然后登录q58论坛, 正常一直回调到用户应用
|
||||||
3. 未登录本系统, 登录了q58论坛, 检查: 用户在接入应用中登录, 然后登录本系统, 正常回调到用户应用
|
3. 未登录本系统, 登录了q58论坛, 检查: 用户在接入应用中登录, 然后登录本系统, 正常回调到用户应用
|
||||||
|
|
||||||
|
## 用户接入本系统oauth2.0认证的方式:
|
||||||
|
|
||||||
|
1. 发起授权请求
|
||||||
|
将用户重定向到授权页面
|
||||||
|
|
||||||
|
const authUrl = 'https://connect.q58.club/oauth/authorize?' +
|
||||||
|
new URLSearchParams({
|
||||||
|
response_type: 'code', // 必填,固定值
|
||||||
|
client_id: 'your_client_id', // 必填,您的应用ID
|
||||||
|
redirect_uri: 'https://your-app.com/callback',
|
||||||
|
state: 'random_state', // 建议提供,防CSRF攻击
|
||||||
|
scope: 'read_profile' // 可选,默认read_profile
|
||||||
|
});
|
||||||
|
|
||||||
|
window.location.href = authUrl;
|
||||||
|
|
||||||
|
2. 处理授权回调
|
||||||
|
在回调地址处理授权结果
|
||||||
|
|
||||||
|
// 获取访问令牌
|
||||||
|
const response = await fetch('https://connect.q58.club/api/oauth/access_token', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
},
|
||||||
|
body: new URLSearchParams({
|
||||||
|
code: '授权码', // 回调参数中的code
|
||||||
|
redirect_uri: 'https://your-app.com/callback'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const { access_token, expires_in } = await response.json();
|
||||||
|
|
||||||
|
3. 获取用户信息
|
||||||
|
使用访问令牌获取用户数据
|
||||||
|
|
||||||
|
const userInfo = await fetch('https://connect.q58.club/api/oauth/user', {
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${access_token}`
|
||||||
|
}
|
||||||
|
}).then(res => res.json());
|
||||||
|
|
||||||
|
// 返回数据示例:
|
||||||
|
{
|
||||||
|
"id": "user_xxx",
|
||||||
|
"email": "user@example.com",
|
||||||
|
"username": "username",
|
||||||
|
"name": "用户昵称",
|
||||||
|
"avatar_url": "https://...",
|
||||||
|
"groups": ["group1", "group2"]
|
||||||
|
}
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
本项目采用 MIT 许可证。详情请见 [LICENSE](LICENSE) 文件。
|
本项目采用 MIT 许可证。详情请见 [LICENSE](LICENSE) 文件。
|
||||||
|
Loading…
x
Reference in New Issue
Block a user