springblade oauth2

阅读数:4 评论数:0

跳转到新版页面

分类

python/Java

正文

1、密码模式

密码模式主要针对可信应用。

/blade-auth/oauth/token

请求头:
    Authorization : Basic c3dvcmQ6c3dvcmRfc2VjcmV0 ("c3dvcmQ6c3dvcmRfc2VjcmV0"为clientId:clientSecret串转换为的base64编码)
    Tenant-Id:000000(替换为对应的租户id)

表单:
    grant_type:password
    scope:all
    username:admin
    password:admin

 

2、刷新token

/blade-auth/oauth/token

请求头:
    Authorization : Basic c3dvcmQ6c3dvcmRfc2VjcmV0 ("c3dvcmQ6c3dvcmRfc2VjcmV0"为clientId:clientSecret串转换为的base64编码)

表单:
    grant_type:refresh_token
    scope:all
    refresh_token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXN0IjoidGVzdCIsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsiYWxsIl0sImV4cCI6MTU1MzE2MTA5NSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6IjE0YmMyYjAyLTgxY2UtNDFiNC04ZTI3LTA5YWE0ZmU4ZWMwYyIsImNsaWVudF9pZCI6ImJsYWRlIn0.jTmioQDq-fSNNn7YCwl3wP0JE-etSWtzLDe545mDbP4

 

3、授权码(暂时没有弄明白)

授权码模式(authorization_code)主要针对第三方应用。

/blade-auth/oauth/token

请求头:
Authorization : Basic c3dvcmQ6c3dvcmRfc2VjcmV0 ("c3dvcmQ6c3dvcmRfc2VjcmV0"为clientId:clientSecret串转换为的base64编码,需要和blade_client表的对应字段相匹配)

表单:
grant_type:authorization_code
scope:all
code:VhYNLR
redirect_uri: http://example.com

 

4、获取到token后如何获取用户信息

(1)拼接请求头

Authorization :bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZXN0IjoidGVzdCIsInVzZXJfbmFtZSI6ImFkbWluIiwic2NvcGUiOlsiYWxsIl0sImV4cCI6MTU1MzE2MTA5NSwiYXV0aG9yaXRpZXMiOlsiUk9MRV9VU0VSIl0sImp0aSI6IjE0YmMyYjAyLTgxY2UtNDFiNC04ZTI3LTA5YWE0ZmU4ZWMwYyIsImNsaWVudF9pZCI6ImJsYWRlIn0.jTmioQDq-fSNNn7YCwl3wP0JE-etSWtzLDe545mDbP4

(2)调用blade-auth/oauth/user-info即可获得对应用户信息。