0

I have created a Python application using Flask-Stormpath and am following the documentation to create groups for authentication. Prior to adding the 5 lines of group creation code the program runs perfectly. Now when I compile the following code (showing just the first part of app.py in this case):

from os import environ

from flask import Flask, session, request, jsonify, g, abort, url_for, redirect, render_template, g, flash, escape
from flask_cors import CORS, cross_origin

from flask_stormpath import StormpathManager, User, login_required, login_user, logout_user, user, groups_required
from stormpath.error import Error as StormpathError
from datetime import timedelta

app = Flask(__name__, static_url_path='/static')

CORS(app)

app.config['DEBUG'] = True
app.config['SECRET_KEY'] = environ.get('SECRET_KEY', 'this_should_be_configured')
app.config['STORMPATH_API_KEY_ID'] = environ.get('STORMPATH_API_KEY_ID')
app.config['STORMPATH_API_KEY_SECRET'] = environ.get('STORMPATH_API_KEY_SECRET')
app.config['STORMPATH_APPLICATION'] = environ.get('STORMPATH_APPLICATION')
app.config['STORMPATH_APPLICATION_HREF'] = environ.get('STORMPATH_APPLICATION_HREF')
app.config['STORMPATH_CLIENT_APIKEY_ID'] = environ.get('STORMPATH_CLIENT_APIKEY_ID')
app.config['STORMPATH_CLIENT_APIKEY_SECRET'] = environ.get('STORMPATH_CLIENT_APIKEY_SECRET')
app.config['STORMPATH_URL'] = environ.get('STORMPATH_URL')
app.config['STORMPATH_ENABLE_LOGIN'] = False
app.config['STORMPATH_ENABLE_REGISTRATION'] = False
app.config['STORMPATH_ENABLE_LOGOUT'] = False

app.config['STORMPATH_COOKIE_DURATION'] = timedelta(minutes=60)

stormpath_manager = StormpathManager(app)
stormpath_manager.login_view = '.login'

# Code to add groups to the application
directory = stormpath_manager.application.default_account_store_mapping.account_store
guests = directory.groups.create({'name': 'guests'})
members = directory.groups.create({'name': 'members'})
managers = directory.groups.create({'name': 'managers'})
admins = directory.groups.create({'name': 'admins'})

I now get a compilation error from within the Stormpath library:

(venv) Marks-MacBook-Pro-2:flask_heroku markschulz$ python app.py Traceback (most recent call last): File "app.py", line 41, in directory = stormpath_manager.application.default_account_store_mapping.account_store File "/Users/markschulz/Projects/maid2match/venv/lib/python2.7/site-packages/flask_stormpath/init.py", line 266, in application ctx = stack.top.app AttributeError: 'NoneType' object has no attribute 'app'

What do I need to do to get past this error? The code line for 'directory' is taken directly from the Stormpath documentation.

1 Answer 1

0

EDIT:

This answer does not work for cases where you are building "a simple application specific admin panel as part of the app so that a business admin type can use."

ORIGINAL ANSWER:

You should use the Stormpath admin panel to achieve this. Once you log into your Stormpath account:

TO CREATE A GROUP

  1. Click the Groups button in the navbar.

  2. Click the Create a Group button.

  3. Select a directory, and enter a name and description.

See here for more detailed steps (with images).

TO ADD AN ACCOUNT TO A GROUP

Click the Groups button in the navbar.

Click Accounts on the left hand menu.

Click Add Existing Account and select the account to be added to the group.

See here for more detailed steps (with images).

2
  • I agree that this is the way to go for group management by an IT admin type. With this code I am looking to build a simple application specific admin panel as part of the app so that a business admin type can use. I wouldn't want to let some of these types loose in the full Stormpath Admin panel. BTW I heard from Stormpath support on API support for group management and of course they stated the obvious: documentation for this is in the Python documentation and not the Python-Flask documentation. Still need to RTFM. Commented Feb 14, 2017 at 22:58
  • Good point. The flask apps I've built have been for IT admin types so I did not consider cases involving business admin types. When you figure this out be sure to add an answer here, I'm now curious about how to get that to work!
    – nessus_pp
    Commented Feb 14, 2017 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.