stormpath/stormpath-sdk-python — pull request #46 by denibertovic (2014-04-17 13:48:56+00:00)
Title: Social login

This pull request is a WIP and adds the initial stuff needed to perform the social logins using Google and Facebook.

We've added a Provider class and wrappers around applicatons.accounts.create for interacting with Providers.

Specifically: applications.get_provider_account(provider_id, **provider_kwargs) is used for requesting a new account from the Provider, which in turn can be checked with account.is_new_account() to see if the account was just copied over from the Provider (ie 200 vs 201 response codes).

We have successfully logged in using Facebook. But the Google Provider is coming back with an error from the StormPath API server.

Google EXAMPLE:

from stormpath.resources.provider import Provider
provider = Provider.GOOGLE

# create a directory with google auth provider
d = c.directories.create({
'name': 'GoogleAuthTest',
'description': 'Testing Google Auth Provider',
'provider': {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'redirect_uri': 'https://api.stormpath.com/oauth2callback',
'provider_id': provider}})

# create a new app
a = c.applications.create({
'name': 'Deni GoogleAuthTestApp',
'description': 'Deni testing app for google auth',
'status': 'enabled'
})

# make the app use the directory
asm = a.account_store_mappings.create({
'application': a,
'account_store': d,
'list_index': 0,
'is_default_account_store': False,
'is_default_group_store': False
})

acc = a.get_provider_account(
provider_id=provider,
code=access_token) # also tried access_token=access_token, and code=code

# The docs are a bit fuzzy on this one

Which returns this:

{"status":400,"code":7200,"message":"Oops! We encountered an unexpected error. Please contact support and explain what you were doing at the time this error occurred.","developerMessage":"Stormpath was not able to complete the request to Google: this can be caused by either a bad Google directory configuration, or the provided account credentials are not valid. Google error message: 400 Bad Request","moreInfo":"http://docs.stormpath.com/errors/7200"}

The facebook example has all the steps as above except we substitute Provider.GOOGLE with Provider.FACEBOOK so:

provider = Provider.FACEBOOK

acc = a.get_provider_account(
provider_id=provider,
access_token=access_token)

print acc # And this works fine