2
Stripe OAuth2 backend, docs at:
3
https://python-social-auth.readthedocs.io/en/latest/backends/stripe.html
5
from .oauth import BaseOAuth2
8
class StripeOAuth2(BaseOAuth2):
9
"""Stripe OAuth2 authentication backend"""
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
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'),
25
def get_user_details(self, response):
26
"""Return user details from Stripe account"""
27
return {'username': response.get('stripe_user_id'),
30
def auth_complete_params(self, state=None):
31
client_id, client_secret = self.get_key_and_secret()
33
'grant_type': 'authorization_code',
34
'client_id': client_id,
35
'scope': self.SCOPE_SEPARATOR.join(self.get_scope()),
36
'code': self.data['code']
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)}
44
def refresh_token_params(self, refresh_token, *args, **kwargs):
45
return {'refresh_token': refresh_token,
46
'grant_type': 'refresh_token'}