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

« back to all changes in this revision

Viewing changes to social_core/backends/ngpvan.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
NGP VAN's `ActionID` Provider
 
3
 
 
4
http://developers.ngpvan.com/action-id
 
5
"""
 
6
from openid.extensions import ax
 
7
 
 
8
from .open_id import OpenIdAuth
 
9
 
 
10
 
 
11
class ActionIDOpenID(OpenIdAuth):
 
12
    """
 
13
    NGP VAN's ActionID OpenID 1.1 authentication backend
 
14
    """
 
15
    name = 'actionid-openid'
 
16
    URL = 'https://accounts.ngpvan.com/Home/Xrds'
 
17
    USERNAME_KEY = 'email'
 
18
 
 
19
    def get_ax_attributes(self):
 
20
        """
 
21
        Return the AX attributes that ActionID responds with, as well as the
 
22
        user data result that it must map to.
 
23
        """
 
24
        return [
 
25
            ('http://openid.net/schema/contact/internet/email', 'email'),
 
26
            ('http://openid.net/schema/contact/phone/business', 'phone'),
 
27
            ('http://openid.net/schema/namePerson/first', 'first_name'),
 
28
            ('http://openid.net/schema/namePerson/last', 'last_name'),
 
29
            ('http://openid.net/schema/namePerson', 'fullname'),
 
30
        ]
 
31
 
 
32
    def setup_request(self, params=None):
 
33
        """
 
34
        Setup the OpenID request
 
35
 
 
36
        Because ActionID does not advertise the availiability of AX attributes
 
37
        nor use standard attribute aliases, we need to setup the attributes
 
38
        manually instead of rely on the parent OpenIdAuth.setup_request()
 
39
        """
 
40
        request = self.openid_request(params)
 
41
 
 
42
        fetch_request = ax.FetchRequest()
 
43
        fetch_request.add(ax.AttrInfo(
 
44
            'http://openid.net/schema/contact/internet/email',
 
45
            alias='ngpvanemail',
 
46
            required=True
 
47
        ))
 
48
 
 
49
        fetch_request.add(ax.AttrInfo(
 
50
            'http://openid.net/schema/contact/phone/business',
 
51
            alias='ngpvanphone',
 
52
            required=False
 
53
        ))
 
54
        fetch_request.add(ax.AttrInfo(
 
55
            'http://openid.net/schema/namePerson/first',
 
56
            alias='ngpvanfirstname',
 
57
            required=False
 
58
        ))
 
59
        fetch_request.add(ax.AttrInfo(
 
60
            'http://openid.net/schema/namePerson/last',
 
61
            alias='ngpvanlastname',
 
62
            required=False
 
63
        ))
 
64
        request.addExtension(fetch_request)
 
65
 
 
66
        return request