Q58Connect/oauth2.0的授权模式.txt
2025-02-23 05:18:32 +08:00

77 lines
2.0 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

授权码模式Authorization Code
第一步:获取授权码
授权码请求链接格式:
http://localhost:8080/oauth/authorize?client_id=123456&response_type=code&scope=all&redirect_url=http://localhost:8080/oauth/token
返回的JSON格式
{
"code": "123456",
"state": "123456"
}
第二步:申请令牌
令牌请求链接格式:
http://localhost:8080/oauth/token?client_id=123456&client_secret=123456&grant_type=authorization_code&code=123456&redirect_url=http://localhost:8080/oauth/callback
返回的JSON格式
{
"access_token": "123456",
"token_type": "bearer",
"scope": "read",
"refresh_token": "123456"
}
资源请求链接格式:
http://localhost:8080/oauth/resource?access_token=123456
返回的JSON格式
{
"resource": "123456"
}
简化模式Implicit
简化模式跳过授权码,直接获取访问令牌,适用于没有后台服务程序的单页面应用。
令牌请求链接格式:
http://localhost:8080/oauth/token?client_id=123456&client_secret=123456&response_type=token&scope=all&redirect_url=http://localhost:8080/oauth/callback
返回的JSON格式
{
"access_token": "123456",
"token_type": "bearer",
"scope": "read",
"refresh_token": "123456"
}
密码模式Password
用户通过客户端使用用户名和密码向授权服务器请求授权,授权服务器向客户端发送访问令牌和更新令牌。
请求链接格式:
http://localhost:8080/oauth/token?client_id=123456&client_secret=123456&grant_type=password&username=admin&password=admin
返回的JSON格式
{
"access_token": "123456",
"token_type": "bearer",
"scope": "read",
"refresh_token": "123456"
}
客户端模式Client Credentials
客户端以自己的名义使用客户端ID和密钥向授权服务器请求授权最简单的授权模式。
请求链接格式:
http://localhost:8080/oauth/token?client_id=123456&client_secret=123456&grant_type=client_credentials
返回的JSON格式
{
"access_token": "123456",
"token_type": "bearer",
"scope": "read",
"refresh_token": "123456"
}