OAuth2授权码模式接口规范
获取授权码
- 请求路径:/oauth/authorize
- 请求方法:浏览器302跳转
- 请求参数:response_type=code,client_id={client_id},redirect_uri={redirect_uri},scope={scope}
- 响应方法:浏览器302跳转响应参数:code={code}
获取token
- 请求路径:/oauth/token请求方法:POST
- 请求Content-Type:application/x-www-form-urlencoded
- 请求header: Authorization:Basic {base64Encoder(client_id+client_secret)}
- 请求参数: grant_type=authorization_code,code={code}, redirect_uri={redirect_uri}
- 响应Content-Type: application/json;charset=UTF-8
- 响应参数:
{
"access_token":"",
"expires_in":60,
"refresh_token":"",
"token_type":"bearer",
"scope":""
}
获取用户信息
- 请求路径:/oauth/userinfo
- 请求方法:GET
- 请求header: Authorization:Bearer {accessToken}
- 响应Content-Type: application/json;charset=UTF-8
- 响应参数:
{
"sub":"e73c6e2e-4bf0-4854-80b4-93ffb0d4f244",
"nickname":"张san",
"name":"张san",
"given_name":"san",
"family_name":"张",
"role_id":[
1,
2,
3,
4
],
"email":"zhangsan@hengshi.com"
}
用户属性只处理一级属性
以上请求方式及参数名称兼容 oauth2 和 oidc 符合规范
https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3