崇之他和她

导航

oauth2.0

1.授权模式,现在不用

2.密码模式现在用

3.springcloudalibaba+oauth2.0+redis

4.应用名称,,网站地址,,转发地址 ,,client_id  client_scept

1.GET请求获取认证 

http://127.0.0.1:8888/oauth/authorize?response_type=code&client_id=client&redirect_uri=http://www.baidu.com&scope=all

返回 code 授权码 :0sL37D   (授权码会显示在重定向后的请求地址中)

2.拿上授权码去请求令牌  POST请求

http://127.0.0.1:8888/oauth/token

第一部分Authorization 中basic Auth   浏览器的上下文里面

{username:client ,password:123456}  这个是需要授权的客户端client的信息 (存在授权服务器上(内存中,或者其他地方拿到))

第二部分body中

{

   "grant_type": "authorization_code",
    "client_id": "client",
    "redirect_uri": http://www.baidu.com,
 “code”:"0sL37D"
    "scope": "all"

}

返回令牌

{
    "access_token": "dfda8182-c356-4914-af72-857f5529014c",
    "token_type": "bearer",
    "expires_in": 43199,
    "scope": "all"
}

 3.根据令牌拿资源  请求各服务路径

第一部分Authorization 中Bearer Token   浏览器的上下文里面

{Token:dfda8182-c356-4914-af72-857f5529014c}  这个是需要授权的客户端client的信息 (存在授权服务器上(内存中,或者其他地方拿到))

第二部分body中

{

 参数根据业务要求,可以没有,请求到那边能获取到东西,则证明访问合法

}

返回user用户相关信息

{
    "username": "admin",
    "password": "$2a$10$sDMmI65nicVvtweriJnZR.7vgSLrPQ3.qWfUIVeM45kPZqQr67fs6",
    "authorities": [
        {
            "authority": "all"
        }
    ],
    "enabled": true,
    "credentialsNonExpired": true,
    "accountNonExpired": true,
    "accountNonLocked": true
}

密码模式

 

2。直接用户名密码请求令牌  POST请求

http://127.0.0.1:8888/oauth/token

第一部分Authorization 中basic Auth   浏览器的上下文里面

{username:client ,password:123456}  这个是需要授权的客户端client的信息 (存在授权服务器上(内存中,或者其他地方拿到))

第二部分body中

{

   "grant_type": "authorization_code", 
    "scope": "all",
 "username": "admin",
 "password": "123456",

}

返回令牌

{
    "access_token": "83fde3f1-fa78-40b7-af62-ecfde20503ab",
    "token_type": "bearer",
    "expires_in": 43199,
    "scope": "all"
}

 3.根据令牌拿资源  请求各服务路径

第一部分Authorization 中Bearer Token   浏览器的上下文里面

{Token:83fde3f1-fa78-40b7-af62-ecfde20503ab}  这个是需要授权的客户端client的信息 (存在授权服务器上(内存中,或者其他地方拿到))

第二部分body中

{

 参数根据业务要求,可以没有,请求到那边能获取到东西,则证明访问合法

}

返回user用户相关信息

{
    "username": "admin",
    "password": "$2a$10$sDMmI65nicVvtweriJnZR.7vgSLrPQ3.qWfUIVeM45kPZqQr67fs6",
    "authorities": [
        {
            "authority": "all"
        }
    ],
    "enabled": true,
    "credentialsNonExpired": true,
    "accountNonExpired": true,
    "accountNonLocked": true
}

 

posted on 2022-04-01 18:03  崇之他和她  阅读(36)  评论(0编辑  收藏  举报