arckinteractive / elgg_oauth_sso
此包最新版本(1.0.0)的许可证信息不可用。
允许其他网站/服务使用 Elgg 作为用户信息的真实来源来实现 SSO。
1.0.0
2020-06-11 21:51 UTC
Requires
- php: >=5.5
- bshaffer/oauth2-server-php: ^1.11
- composer/installers: ~1.0
This package is auto-updated.
Last update: 2024-09-12 08:20:48 UTC
README
允许其他网站使用 elgg 服务器作为 OAuth 身份管理器。
- 在
/admin/applications
上注册一个新的应用程序。 - 通过让用户在
[url]/oauth/authorize?client_id=xxxxxxxx&state=xxxxxxxx&response_type=code&scope=user
登录来授权用户,其中 client_id 是应用程序生成的 ID,state 是一个随机字符串,用于防止 CSRF 攻击。 - 如果需要,用户将登录并授权应用程序。
- 用户将被重定向回 redirect_uri,并在查询参数中包含原始状态和一个代码:
[redirect_uri]?state=xxxxxx&code=xxxxxxxx
- 通过带有以下 body 参数的 POST 请求到
/oauth/token
{
client_id: xxxxxxxx,
client_secret: xxxxxxx,
grant_type: 'authorization_code',
redirect_uri: 'https://xxxxxxxxxxxxx',
code: xxxxxxxxxx
}
- 结果将是一个访问令牌
{
"access_token": "369e27dae447d3856fc538a217536b186cea1bc3",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "user",
"refresh_token": "3c706473a576815c503a119626d674331becc4c8"
}
- 访问令牌在头部:
Authorization: Bearer 369e27dae447d3856fc538a217536b186cea1bc3
用于未来的 OAuth API 调用 - 从 GET 端点
/oauth/api/me
获取用户信息
{
"name": "Matt Beckett",
"username": "mbeckett",
"email": "matt@arckinteractive.com"
}
- 如果需要,使用刷新令牌获取新的访问令牌,通过以下 body 参数向
/oauth/token
发送 POST 请求
{
client_id: xxxxxxxx,
client_secret: xxxxxxx,
grant_type: 'refresh_token',
refresh_token: xxxxxxxxxx
}