【问题标题】:keycloak and social-auth-app-django : how to get user's groupskeycloak 和 social-auth-app-django :如何获取用户组
【发布时间】:2020-01-28 22:54:43
【问题描述】:

我的设置:用于 web 和 keycloak 的 docker 容器。

网络容器: Django 2.2

social-auth-app-django==3.1.0

social-auth-core==3.2.0

keycloak 容器:拉取jboss/keycloak 图像。

问题是关于代码的: 我正在使用social-auth-app-django(不是python-keycloak),登录和注销已经可以使用了。是否有一个电话会给我用户所属的组列表(当然我说的不是“django”用户和组,而是“keycloak”用户和组,它们是通过 keycloak 管理界面设置的)?我有我的pipelines.py 文件,我试图在其中创建一个自定义管道以从userbackend 对象中提取此信息,例如

print("backend.get_user", backend.get_user(user_id))

这给了我回报:

{'username': 'xxxx', 'email': 'xxxx', 'fullname': 'xxxx', 'first_name': 'xxxx', 'last_name': 'xxxx'}

print("backend.extra_data", backend.extra_data(user, user_id, response)) 还给我

{'auth_time': 1579705033, 'access_token': 'xxxx', 'token_type': '承载者'}

我尝试过的其他几件事不返回组信息。 文档Python Social Auth’s documentation 没有帮助。

如何使用 social-auth-app-django 中可用的任何内容获取给定用户的组列表?

【问题讨论】:

    标签: django oauth pipeline keycloak python-social-auth


    【解决方案1】:

    API keycloak 文档中没有记录,我通过猜测这可能是什么找到了解决方案:-)。

    headers = {'Authorization': 'Bearer %s' % token}
    groups_request = r
    hequests.get('http://yoursite:8080/auth/admin/realms/<realm_name>/users/<user_id>/groups', headers=headers)
    

    【讨论】:

      猜你喜欢
      • 2019-10-19
      • 2020-10-13
      • 2020-09-23
      • 2013-12-11
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 2021-07-31
      相关资源
      最近更新 更多