Skip to content

Instantly share code, notes, and snippets.

@rdegges
Created May 16, 2014 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdegges/1155b9e3fc3432c0f7b2 to your computer and use it in GitHub Desktop.
Save rdegges/1155b9e3fc3432c0f7b2 to your computer and use it in GitHub Desktop.
Stormpath Python Quickstart Code Sample
"""
quickstart.py
~~~~~~~~~~~~~
Code from the Stormpath Python Quickstart:
http://docs.stormpath.com/python/quickstart/
You can run this code by typing:
$ python quickstart.py
In your terminal.
Questions? Email us! support@stormpath.com
"""
from os.path import expanduser
from stormpath.client import Client
# Create a new Stormpath Client.
client = Client(api_key_file_location=expanduser('~/.stormpath/apiKey.properties'))
# Create a new Stormpath Application.
application = client.applications.create({
'name': 'My Awesome Application',
'description': 'Super awesome!',
}, create_directory=True)
# Create a new Stormpath Account.
account = application.accounts.create({
'given_name': 'Joe',
'surname': 'Stormtrooper',
'username': 'tk455',
'email': 'stormtrooper@stormpath.com',
'password': 'Changeme1',
'custom_data': {
'favorite_color': 'white',
},
})
# Search for our newly created account, and print the user's name.
for account in application.accounts.search({'email': 'stormtrooper@stormpath.com'}):
print account.given_name, account.surname
# Log a user into their account using email / password.
account = application.authenticate_account('stormtrooper@stormpath.com', 'Changeme1').account
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment