ToB企服应用市场:ToB评测及商务社交产业平台

标题: keycloak~关于授权码认证中的scope的实践 [打印本页]

作者: tsx81429    时间: 2024-9-25 09:33
标题: keycloak~关于授权码认证中的scope的实践
媒介

1. scope 参数的作用


  1. [/code][size=4]2. 在不同阶段使用 scope[/size]
  2. [list]
  3. [*][b]授权请求阶段[/b] (/protocol/openid-connect/auth):
  4. [list]
  5. [*]可以传递 scope 参数,以便在用户同意授权时,明确所请求的权限。
  6. [/list]
  7. [*][b]令牌请求阶段[/b] (/protocol/openid-connect/token):
  8. [list]
  9. [*]也可以在此阶段传递 scope,但通常环境下,假如在授权请求中已指定 scope,则不需要在此再次指定;
  10. [*]在授权中指定了scope,这里再指定是无效的,以授权中指定的值为准
  11. [/list]
  12. [/list][size=4]3. 示例[/size]
  13. 以下是一个获取授权码的请求示例:
  14. [code]GET /auth/realms/{realm}/protocol/openid-connect/auth?
  15. response_type=code&
  16. client_id={client_id}&
  17. redirect_uri={redirect_uri}&
  18. scope=openid profile
复制代码
4. 总结

实践

oauth2授权码认证的过程

1. 配置客户端及scope模板


2. 获取授权码

3. 表单认证

4. 获取token

  1. grant_type:authorization_code
  2. code:3be438fe-8651-4a84-8141-976b76e671e1.75cab95f-a1ec-4b9b-9a6e-8f1ecb651cd6.61d819de-33e4-4006-ae66-dd7609ea2d3e
  3. client_id:dahengshuju
  4. client_secret:9e3de70f-d5cd-4d11-a8aa-85fd3af13265
  5. scope:profile
复制代码
  1. {
  2.     "exp": 1727233162,
  3.     "iat": 1727231362,
  4.     "auth_time": 1727229121,
  5.     "jti": "bb296d9d-d521-45b1-aab9-8cb6bea0ddc3",
  6.     "iss": "https://xx.xx.com/auth/realms/xx",
  7.     "sub": "347c9e9e-076c-45e3-be74-c482fffcc6e5",
  8.     "typ": "Bearer",
  9.     "azp": "dahengshuju",
  10.     "session_state": "75cab95f-a1ec-4b9b-9a6e-8f1ecb651cd6",
  11.     "acr": "0",
  12.     "scope": "email profile",
  13.     "email_verified": false,
  14.     "preferred_username": "test",
  15.     "locale": "zh-CN",
  16.     "email": "bfyxzls@gmail.com"
  17. }
复制代码
  1. {
  2.     "exp": 1727233521,
  3.     "iat": 1727231721,
  4.     "auth_time": 1727229121,
  5.     "jti": "f7de8ad9-7558-4f4a-8761-8724f685febb",
  6.     "iss": "https://xx.xx.com/auth/realms/xx",
  7.     "sub": "347c9e9e-076c-45e3-be74-c482fffcc6e5",
  8.     "typ": "Bearer",
  9.     "azp": "dahengshuju",
  10.     "session_state": "75cab95f-a1ec-4b9b-9a6e-8f1ecb651cd6",
  11.     "acr": "0",
  12.     "scope": "profile",
  13.     "preferred_username": "test",
  14.     "locale": "zh-CN"
  15. }
复制代码
5. 通过access_token获取用户信息

  1. {
  2.     "sub": "347c9e9e-076c-45e3-be74-c482fffcc6e5",
  3.     "email_verified": false,
  4.     "preferred_username": "test",
  5.     "locale": "zh-CN",
  6.     "email": "xxx@gmail.com"
  7. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4