~ubuntu-branches/debian/sid/social-auth-core/sid

« back to all changes in this revision

Viewing changes to social_core/backends/gae.py

  • Committer: Package Import Robot
  • Author(s): Andre Bianchi
  • Date: 2018-02-22 19:49:12 UTC
  • Revision ID: package-import@ubuntu.com-20180222194912-4lqv8mlhnqc4ncd3
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Google App Engine support using User API
 
3
"""
 
4
from __future__ import absolute_import
 
5
 
 
6
from google.appengine.api import users
 
7
 
 
8
from .base import BaseAuth
 
9
from ..exceptions import AuthException
 
10
 
 
11
 
 
12
class GoogleAppEngineAuth(BaseAuth):
 
13
    """GoogleAppengine authentication backend"""
 
14
    name = 'google-appengine'
 
15
 
 
16
    def get_user_id(self, details, response):
 
17
        """Return current user id."""
 
18
        user = users.get_current_user()
 
19
        if user:
 
20
            return user.user_id()
 
21
 
 
22
    def get_user_details(self, response):
 
23
        """Return user basic information (id and email only)."""
 
24
        user = users.get_current_user()
 
25
        return {'username': user.user_id(),
 
26
                'email': user.email(),
 
27
                'fullname': '',
 
28
                'first_name': '',
 
29
                'last_name': ''}
 
30
 
 
31
    def auth_url(self):
 
32
        """Build and return complete URL."""
 
33
        return users.create_login_url(self.redirect_uri)
 
34
 
 
35
    def auth_complete(self, *args, **kwargs):
 
36
        """Completes login process, must return user instance."""
 
37
        if not users.get_current_user():
 
38
            raise AuthException('Authentication error')
 
39
        kwargs.update({'response': '', 'backend': self})
 
40
        return self.strategy.authenticate(*args, **kwargs)