/usr/share/pyshared/social_auth/backends/stripe.py is in python-django-social-auth 0.7.23-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | """
Stripe OAuth2 support.
This backend adds support for Stripe OAuth2 service. The settings
STRIPE_APP_ID and STRIPE_API_SECRET must be defined with the values
given by Stripe application registration process.
"""
from social_auth.backends import BaseOAuth2, OAuthBackend
from social_auth.exceptions import AuthFailed, AuthCanceled
class StripeBackend(OAuthBackend):
"""Stripe OAuth2 authentication backend"""
name = 'stripe'
ID_KEY = 'stripe_user_id'
EXTRA_DATA = [
('stripe_publishable_key', 'stripe_publishable_key'),
('access_token', 'access_token'),
('livemode', 'livemode'),
('token_type', 'token_type'),
('refresh_token', 'refresh_token'),
('stripe_user_id', 'stripe_user_id'),
]
def get_user_details(self, response):
"""Return user details from Stripe account"""
return {'username': response.get('stripe_user_id'),
'email': ''}
class StripeAuth(BaseOAuth2):
"""Facebook OAuth2 support"""
AUTH_BACKEND = StripeBackend
AUTHORIZATION_URL = 'https://connect.stripe.com/oauth/authorize'
ACCESS_TOKEN_URL = 'https://connect.stripe.com/oauth/token'
SCOPE_VAR_NAME = 'STRIPE_SCOPE'
SETTINGS_KEY_NAME = 'STRIPE_APP_ID'
SETTINGS_SECRET_NAME = 'STRIPE_APP_SECRET'
REDIRECT_STATE = False
def process_error(self, data):
if self.data.get('error'):
error = self.data.get('error_description') or self.data['error']
if self.data['error'] == 'access_denied':
raise AuthCanceled(self, error)
else:
raise AuthFailed(self, error)
def auth_params(self, state=None):
client_id, client_secret = self.get_key_and_secret()
params = {
'response_type': self.RESPONSE_TYPE,
'client_id': client_id,
}
if state:
params['state'] = state
return params
def auth_complete_params(self, state=None):
client_id, client_secret = self.get_key_and_secret()
return {
'grant_type': 'authorization_code',
'client_id': client_id,
'scope': self.SCOPE_SEPARATOR.join(self.get_scope()),
'code': self.data['code']
}
@classmethod
def auth_headers(cls):
client_id, client_secret = cls.get_key_and_secret()
return {
'Accept': 'application/json',
'Authorization': 'Bearer %s' % client_secret
}
@classmethod
def refresh_token_params(cls, refresh_token):
return {
'refresh_token': refresh_token,
'grant_type': 'refresh_token'
}
# Backend definition
BACKENDS = {
'stripe': StripeAuth
}
|