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

« back to all changes in this revision

Viewing changes to social_core/backends/stripe.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
Stripe OAuth2 backend, docs at:
 
3
    https://python-social-auth.readthedocs.io/en/latest/backends/stripe.html
 
4
"""
 
5
from .oauth import BaseOAuth2
 
6
 
 
7
 
 
8
class StripeOAuth2(BaseOAuth2):
 
9
    """Stripe OAuth2 authentication backend"""
 
10
    name = 'stripe'
 
11
    ID_KEY = 'stripe_user_id'
 
12
    AUTHORIZATION_URL = 'https://connect.stripe.com/oauth/authorize'
 
13
    ACCESS_TOKEN_URL = 'https://connect.stripe.com/oauth/token'
 
14
    ACCESS_TOKEN_METHOD = 'POST'
 
15
    REDIRECT_STATE = False
 
16
    EXTRA_DATA = [
 
17
        ('stripe_publishable_key', 'stripe_publishable_key'),
 
18
        ('access_token', 'access_token'),
 
19
        ('livemode', 'livemode'),
 
20
        ('token_type', 'token_type'),
 
21
        ('refresh_token', 'refresh_token'),
 
22
        ('stripe_user_id', 'stripe_user_id'),
 
23
    ]
 
24
 
 
25
    def get_user_details(self, response):
 
26
        """Return user details from Stripe account"""
 
27
        return {'username': response.get('stripe_user_id'),
 
28
                'email': ''}
 
29
 
 
30
    def auth_complete_params(self, state=None):
 
31
        client_id, client_secret = self.get_key_and_secret()
 
32
        return {
 
33
            'grant_type': 'authorization_code',
 
34
            'client_id': client_id,
 
35
            'scope': self.SCOPE_SEPARATOR.join(self.get_scope()),
 
36
            'code': self.data['code']
 
37
        }
 
38
 
 
39
    def auth_headers(self):
 
40
        client_id, client_secret = self.get_key_and_secret()
 
41
        return {'Accept': 'application/json',
 
42
                'Authorization': 'Bearer {0}'.format(client_secret)}
 
43
 
 
44
    def refresh_token_params(self, refresh_token, *args, **kwargs):
 
45
        return {'refresh_token': refresh_token,
 
46
                'grant_type': 'refresh_token'}