stormpath 无法为 google 登录目录创建组

stormpath can't create groups for google sign in directory

已安装 stormpath 并使用 google 登录进行注册和登录。 现在我正在尝试使用此

在 stormpath 的 google 目录中创建组
from stormpath.client import Client
stormpath_client = Client(id=STORMPATH_CLIENT_APIKEY_ID, secret=STORMPATH_CLIENT_APIKEY_SECRET)
directory = stormpath_client.applications[0].account_store_mappings[1].account_store
directory.groups.create({'name': 'admins'})

基于this toturial

我收到错误

Cannot create nor edit accounts of externally managed directories.

如果我尝试在 stormpath 控制台中创建组,我会遇到同样的错误。

如何给不同的用户不同的权限?

Stormpath 不允许您为社交目录(例如此处的 Google 目录)创建群组。

你需要做的是创建一个普通的 Stormpath 目录(不是社交目录),在那里创建你的用户,然后你可以做一些事情,比如创建组等。

我(个人)喜欢做的是:

  • 用户通过 Google 登录后,我将在我的主 Stormpath 目录中创建该用户帐户的副本。
  • 然后我将在 Stormpath 目录中使用该用户的副本作为该用户的 'main' 帐户,并在那里创建组等。

我在 python Flask

中为这个 stormpath 解决方法创建了示例代码要点

environment.py https://gist.github.com/ohadperry/f77a26ce758efa2990cb

authentication_controller.py https://gist.github.com/ohadperry/338e7e689d8c64158c06

stormpath_helper.py https://gist.github.com/ohadperry/50951e68f2375f0b9002

基本逻辑是:

  1. 使用 google 用户登录。
  2. 在云目录中查找或创建一个使用
  3. 使用flask登录切换到新的云用户

    from flask.ext.stormpath import User as StormpathUser
    from flask.ext.login import login_user 
    new_user_account.__class__ = StormpathUser
    # switching the session
    login_user(new_user_account, remember=True)
    

这个问题现在也可以在 Stormpath 管理面板中解决。基本过程与其他两个答案中描述的过程非常相似,但现在只需在 Stormpath 网站中单击几下即可实现。

程序

  1. Log in 到您的 Stormpath 帐户。

  2. 单击顶部导航栏中的 Applications

  3. 点击你的应用然后select Policies在左手 菜单.

  4. Account Linking Policy 下,将 Status 设置为 EnabledAutomatic ProvisioningEnabled.

  5. 就是这样!

完成后,当用户首次使用社交登录登录时,Stormpath 将在应用程序的默认目录下创建另一个链接到社交登录帐户的帐户。您现在可以创建组并将默认目录中的用户帐户分配给该组,这将进一步将社交登录添加到该组。这是有效的,因为两个帐户(社交登录和在默认目录中创建的另一个)相互链接。

有关详细信息,请参阅 here