Skip to content

Instantly share code, notes, and snippets.

@geeknam
Created November 2, 2014 12:10
Show Gist options
  • Save geeknam/045ab1b9a99b8089bf90 to your computer and use it in GitHub Desktop.
Save geeknam/045ab1b9a99b8089bf90 to your computer and use it in GitHub Desktop.
python-social-auth mobile support
from social.actions import do_complete
from social.apps.django_app import load_strategy
from social.apps.django_app.default.models import UserSocialAuth
from social.apps.django_app.views import _do_login
from social.backends.utils import load_backends
from social.exceptions import MissingBackend
def psa_mobile(request, *args, **kwargs):
"""
Endpoint used by mobile app to authenticate using OAuth2
access tokens
"""
provider = request.POST.get('provider')
access_token = request.POST.get('access_token')
data = {'success': False}
try:
request.social_strategy = load_strategy(
request=request, backend=provider,
redirect_uri=None, *args, **kwargs
)
except MissingBackend:
raise Http404('Backend not found')
try:
user = request.social_strategy.backend.do_auth(access_token)
if user:
_do_login(request.social_strategy, user)
data['success'] = True
except HTTPError:
pass
except AttributeError:
# redirect to register endpoint
# Return response here
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment