Created
May 16, 2014 22:33
-
-
Save rdegges/1155b9e3fc3432c0f7b2 to your computer and use it in GitHub Desktop.
Stormpath Python Quickstart Code Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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! [email protected] | |
""" | |
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': '[email protected]', | |
'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': '[email protected]'}): | |
print account.given_name, account.surname | |
# Log a user into their account using email / password. | |
account = application.authenticate_account('[email protected]', 'Changeme1').account |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment