Advertisement
Guest User

UNTI backend

a guest
Apr 4th, 2018
1,362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. Пример авторизационного бэкенда для клиента:
  2. from social.backends.oauth import BaseOAuth2
  3.  
  4.  
  5. class UNTIBackend(BaseOAuth2):
  6.  
  7.     name = 'sso_unti-oauth2'
  8.     ID_KEY = 'username'
  9.     AUTHORIZATION_URL = '{}/oauth2/authorize'.format(settings.SSO_UNTI_URL)
  10.     ACCESS_TOKEN_URL = '{}/oauth2/access_token'.format(settings.SSO_UNTI_URL)
  11.     USER_DATA_URL = '{url}/oauth2/access_token/{access_token}/'
  12.     DEFAULT_SCOPE = []
  13.     REDIRECT_STATE = False
  14.     ACCESS_TOKEN_METHOD = 'POST'
  15.  
  16.     PIPELINE = (
  17.         'social.pipeline.social_auth.social_details',
  18.         'social.pipeline.social_auth.social_uid',
  19.         'social.pipeline.social_auth.auth_allowed',
  20.         'social.pipeline.social_auth.social_user',
  21.         'social.pipeline.user.get_username',
  22.         'social.pipeline.user.create_user',
  23.         'social.pipeline.social_auth.associate_user',
  24.         'social.pipeline.social_auth.load_extra_data',
  25.         'social.pipeline.user.user_details',
  26.     )
  27.  
  28.     skip_email_verification = True
  29.  
  30.     def get_user_details(self, response):
  31.         return response
  32.    
  33.     def user_data(self, access_token, *args, **kwargs):
  34.         return self.get_json(
  35.             '{}/users/me'.format(settings.SSO_UNTI_URL),
  36.             params={'access_token': access_token},
  37.             headers={'Authorization': 'Bearer {}'.format(access_token)},
  38.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement