Search code examples
pythongoogle-identity-toolkitstormpath

stormpath can't create groups for google sign in directory


Installed stormpath and using google sign in to register and sign in. Now I'm trying to create groups in the google directory in stormpath using this

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'})

based on this toturial

I get and error

Cannot create nor edit accounts of externally managed directories.

I get the same error if I try to create groups in the stormpath console.

enter image description here

How do I give different users different permissions?


Solution

  • I've created a gist for sample code for this stormpathworkaround in python Flask

    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

    The basic logic is :

    1. log in with the google user.
    2. find or create a use in the cloud directory
    3. switch to the new cloud user using flask login

      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)