Skip to content

Commit

Permalink
Merge branch 'master' into refactoring/improve-vk-api
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel authored Dec 15, 2021
2 parents 0e2e643 + 1ea27e8 commit eb9dfd2
Show file tree
Hide file tree
Showing 107 changed files with 486 additions and 334 deletions.
12 changes: 0 additions & 12 deletions .github/stale.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: check-json
- id: debug-statements
- id: mixed-line-ending
args: [--fix=lf]
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Add fields that populate on create but not update `SOCIAL_AUTH_IMMUTABLE_USER_FIELDS`
- Add Gitea oauth2 backend
- Add Twitch OpenId backend

### Changed
- Fixed Slack user identity API call with Bearer headers
- Fixed microsoft-graph login error
- Fixed Twitch OAuth2 backend


## [4.1.0](https://github.com/python-social-auth/social-core/releases/tag/4.1.0) - 2021-03-01
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import re

from os.path import join, dirname
Expand All @@ -21,7 +20,7 @@
def long_description():
try:
return open(join(dirname(__file__), 'README.md')).read()
except IOError:
except OSError:
return None


Expand All @@ -33,12 +32,12 @@ def read_version():


def read_requirements(filename):
with open(filename, 'r') as file:
with open(filename) as file:
return [line for line in file.readlines() if not line.startswith('-')]


def read_tests_requirements(filename):
return read_requirements('social_core/tests/{0}'.format(filename))
return read_requirements(f'social_core/tests/{filename}')


requirements = read_requirements('requirements-base.txt')
Expand Down
2 changes: 1 addition & 1 deletion social_core/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def do_complete(backend, login, user=None, redirect_name='next',
if redirect_value and redirect_value != url:
redirect_value = quote(redirect_value)
url += ('&' if '?' in url else '?') + \
'{0}={1}'.format(redirect_name, redirect_value)
f'{redirect_name}={redirect_value}'

if backend.setting('SANITIZE_REDIRECTS', True):
allowed_hosts = backend.setting('ALLOWED_REDIRECT_HOSTS', []) + \
Expand Down
4 changes: 2 additions & 2 deletions social_core/backends/apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def decode_id_token(self, id_token):
audience=self.get_audience(),
algorithms=['RS256'],
)
except PyJWTError:
raise AuthFailed(self, 'Token validation failed')
except PyJWTError as error:
raise AuthFailed(self, f'Token validation failed by {error}')

return decoded

Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/asana.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_user_details(self, response):

def user_data(self, access_token, *args, **kwargs):
return self.get_json(self.USER_DATA_URL, headers={
'Authorization': 'Bearer {}'.format(access_token)
'Authorization': f'Bearer {access_token}'
})

def extra_data(self, user, uid, response, details=None, *args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions social_core/backends/atlassian.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def get_user_details(self, response):

def user_data(self, access_token, *args, **kwargs):
resources = self.get_json('https://api.atlassian.com/oauth/token/accessible-resources',
headers={'Authorization': 'Bearer {}'.format(access_token)})
headers={'Authorization': f'Bearer {access_token}'})
user_info = self.get_json('https://api.atlassian.com/ex/jira/{}/rest/api/2/myself'.format(resources[0]['id']),
headers={'Authorization': 'Bearer {}'.format(access_token)})
headers={'Authorization': f'Bearer {access_token}'})
user_info['resources'] = resources
return user_info
4 changes: 2 additions & 2 deletions social_core/backends/azuread.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AzureADOAuth2(BaseOAuth2):
ACCESS_TOKEN_URL = 'https://login.microsoftonline.com/common/oauth2/token'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False
DEFAULT_SCOPE = ['openid', 'profile', 'user_impersonation']
DEFAULT_SCOPE = ['openid', 'profile', 'user_impersonation', 'email']
EXTRA_DATA = [
('access_token', 'access_token'),
('id_token', 'id_token'),
Expand All @@ -70,7 +70,7 @@ def get_user_details(self, response):
response.get('family_name', '')
)
return {'username': fullname,
'email': response.get('upn'),
'email': response.get('email', response.get('upn')),
'fullname': fullname,
'first_name': first_name,
'last_name': last_name}
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/azuread_b2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_public_key(self, kid):
for key in resp.json()['keys']:
if key['kid'] == kid:
return self.jwt_key_to_pem(key)
raise DecodeError('Cannot find kid={}'.format(kid))
raise DecodeError(f'Cannot find kid={kid}')

def user_data(self, access_token, *args, **kwargs):
response = kwargs.get('response')
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/azuread_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_certificate(self, kid):
x5c = key['x5c'][0]
break
else:
raise DecodeError('Cannot find kid={}'.format(kid))
raise DecodeError(f'Cannot find kid={kid}')

return load_der_x509_certificate(base64.b64decode(x5c),
default_backend())
Expand Down
6 changes: 3 additions & 3 deletions social_core/backends/beats.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def get_user_id(self, details, response):

def auth_headers(self):
return {
'Authorization': 'Basic {0}'.format(base64.urlsafe_b64encode(
('{0}:{1}'.format(*self.get_key_and_secret()).encode())
'Authorization': 'Basic {}'.format(base64.urlsafe_b64encode(
'{}:{}'.format(*self.get_key_and_secret()).encode()
))
}

Expand Down Expand Up @@ -61,5 +61,5 @@ def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json(
'https://partner.api.beatsmusic.com/v1/api/me',
headers={'Authorization': 'Bearer {0}'.format(access_token)}
headers={'Authorization': f'Bearer {access_token}'}
)
4 changes: 2 additions & 2 deletions social_core/backends/chatwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ChatworkOAuth2(BaseOAuth2):

def api_url(self, path):
api_url = self.setting('API_URL') or self.API_URL
return '{0}{1}'.format(api_url.rstrip('/'), path)
return '{}{}'.format(api_url.rstrip('/'), path)

def auth_headers(self):
return {
'Authorization': b'Basic ' + base64.b64encode(
'{0}:{1}'.format(*self.get_key_and_secret()).encode()
'{}:{}'.format(*self.get_key_and_secret()).encode()
)
}

Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/coding.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def user_data(self, access_token, *args, **kwargs):
def _user_data(self, access_token, path=None):
url = urljoin(
self.api_url(),
'account/current_user{0}'.format(path or '')
'account/current_user{}'.format(path or '')
)
return self.get_json(url, params={'access_token': access_token})
8 changes: 4 additions & 4 deletions social_core/backends/cognito.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def user_pool_domain(self):
return self.setting('POOL_DOMAIN')

def authorization_url(self):
return '{}/login'.format(self.user_pool_domain())
return f'{self.user_pool_domain()}/login'

def access_token_url(self):
return '{}/oauth2/token'.format(self.user_pool_domain())
return f'{self.user_pool_domain()}/oauth2/token'

def user_data_url(self):
return '{}/oauth2/userInfo'.format(self.user_pool_domain())
return f'{self.user_pool_domain()}/oauth2/userInfo'

def get_user_details(self, response):
"""Return user details from their cognito pool account"""
Expand All @@ -38,7 +38,7 @@ def user_data(self, access_token, *args, **kwargs):
"""Grab user profile information from cognito."""
response = self.get_json(
url=self.user_data_url(),
headers={'Authorization': 'Bearer {}'.format(access_token)},
headers={'Authorization': f'Bearer {access_token}'},
)

user_data = {
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/coursera.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def user_data(self, access_token, *args, **kwargs):
)

def get_auth_header(self, access_token):
return {'Authorization': 'Bearer {0}'.format(access_token)}
return {'Authorization': f'Bearer {access_token}'}
62 changes: 31 additions & 31 deletions social_core/backends/discord.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
"""
Discord Auth OAuth2 backend, docs at:
https://discord.com/developers/docs/topics/oauth2
"""
from .oauth import BaseOAuth2


class DiscordOAuth2(BaseOAuth2):
name = 'discord'
HOSTNAME = 'discord.com'
AUTHORIZATION_URL = 'https://%s/api/oauth2/authorize' % HOSTNAME
ACCESS_TOKEN_URL = 'https://%s/api/oauth2/token' % HOSTNAME
ACCESS_TOKEN_METHOD = 'POST'
REVOKE_TOKEN_URL = 'https://%s/api/oauth2/token/revoke' % HOSTNAME
REVOKE_TOKEN_METHOD = 'GET'
DEFAULT_SCOPE = ['identify']
SCOPE_SEPARATOR = '+'
REDIRECT_STATE = False
EXTRA_DATA = [
('expires_in', 'expires'),
('refresh_token', 'refresh_token')
]

def get_user_details(self, response):
return {'username': response.get('username'),
'email': response.get('email') or ''}

def user_data(self, access_token, *args, **kwargs):
url = 'https://%s/api/users/@me' % self.HOSTNAME
auth_header = {'Authorization': 'Bearer %s' % access_token}
return self.get_json(url, headers=auth_header)
"""
Discord Auth OAuth2 backend, docs at:
https://discord.com/developers/docs/topics/oauth2
"""
from .oauth import BaseOAuth2


class DiscordOAuth2(BaseOAuth2):
name = 'discord'
HOSTNAME = 'discord.com'
AUTHORIZATION_URL = 'https://%s/api/oauth2/authorize' % HOSTNAME
ACCESS_TOKEN_URL = 'https://%s/api/oauth2/token' % HOSTNAME
ACCESS_TOKEN_METHOD = 'POST'
REVOKE_TOKEN_URL = 'https://%s/api/oauth2/token/revoke' % HOSTNAME
REVOKE_TOKEN_METHOD = 'GET'
DEFAULT_SCOPE = ['identify']
SCOPE_SEPARATOR = '+'
REDIRECT_STATE = False
EXTRA_DATA = [
('expires_in', 'expires'),
('refresh_token', 'refresh_token')
]

def get_user_details(self, response):
return {'username': response.get('username'),
'email': response.get('email') or ''}

def user_data(self, access_token, *args, **kwargs):
url = 'https://%s/api/users/@me' % self.HOSTNAME
auth_header = {'Authorization': 'Bearer %s' % access_token}
return self.get_json(url, headers=auth_header)
2 changes: 1 addition & 1 deletion social_core/backends/discourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def auth_url(self):
'sso': base_64_payload,
'sig': payload_signature
})
return '{0}?{1}'.format(self.get_idp_url(), encoded_params)
return f'{self.get_idp_url()}?{encoded_params}'

def get_idp_url(self):
return self.setting('SERVER_URL') + '/session/sso_provider'
Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/douban.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ def user_data(self, access_token, *args, **kwargs):
"""Return user data provided"""
return self.get_json(
'https://api.douban.com/v2/user/~me',
headers={'Authorization': 'Bearer {0}'.format(access_token)}
headers={'Authorization': f'Bearer {access_token}'}
)
2 changes: 1 addition & 1 deletion social_core/backends/dribbble.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ def user_data(self, access_token, *args, **kwargs):
return self.get_json(
'https://api.dribbble.com/v1/user',
headers={
'Authorization': 'Bearer {0}'.format(access_token)
'Authorization': f'Bearer {access_token}'
})
2 changes: 1 addition & 1 deletion social_core/backends/dropbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json(
'https://api.dropboxapi.com/2/users/get_current_account',
headers={'Authorization': 'Bearer {0}'.format(access_token)},
headers={'Authorization': f'Bearer {access_token}'},
method='POST'
)
2 changes: 1 addition & 1 deletion social_core/backends/eveonline.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def user_data(self, access_token, *args, **kwargs):
"""Get Character data from EVE server"""
return self.get_json(
'https://login.eveonline.com/oauth/verify',
headers={'Authorization': 'Bearer {0}'.format(access_token)}
headers={'Authorization': f'Bearer {access_token}'}
)
2 changes: 1 addition & 1 deletion social_core/backends/exacttarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_user_id(self, details, response):
'email': '[email protected]'
}
"""
return '{0}'.format(details.get('id'))
return '{}'.format(details.get('id'))

def uses_redirect(self):
return False
Expand Down
6 changes: 3 additions & 3 deletions social_core/backends/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
AuthMissingParameter


API_VERSION = 8.0
API_VERSION = 14.0


class FacebookOAuth2(BaseOAuth2):
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_user_details(self, response):

def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
params = self.setting('PROFILE_EXTRA_PARAMS', {})
params = self.setting('PROFILE_EXTRA_PARAMS', {}).copy()
params['access_token'] = access_token

if self.setting('APPSECRET_PROOF', True):
Expand Down Expand Up @@ -213,7 +213,7 @@ def auth_html(self):
def load_signed_request(self, signed_request):
def base64_url_decode(data):
data = data.encode('ascii')
data += '='.encode('ascii') * (4 - (len(data) % 4))
data += b'=' * (4 - (len(data) % 4))
return base64.urlsafe_b64decode(data)

key, secret = self.get_key_and_secret()
Expand Down
4 changes: 2 additions & 2 deletions social_core/backends/fitbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ def user_data(self, access_token, *args, **kwargs):
)['user']

def auth_headers(self):
tokens = '{0}:{1}'.format(*self.get_key_and_secret())
tokens = '{}:{}'.format(*self.get_key_and_secret())
tokens = base64.urlsafe_b64encode(tokens.encode())
tokens = tokens.decode()
return {
'Authorization': 'Basic {0}'.format(tokens)
'Authorization': f'Basic {tokens}'
}
1 change: 0 additions & 1 deletion social_core/backends/gae.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Google App Engine support using User API
"""
from __future__ import absolute_import

from google.appengine.api import users

Expand Down
2 changes: 1 addition & 1 deletion social_core/backends/gitea.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GiteaOAuth2 (BaseOAuth2):

def api_url(self, path):
api_url = self.setting('API_URL') or self.API_URL
return '{0}{1}'.format(api_url.rstrip('/'), path)
return '{}{}'.format(api_url.rstrip('/'), path)

def authorization_url(self):
return self.api_url('/login/oauth/authorize')
Expand Down
Loading

0 comments on commit eb9dfd2

Please sign in to comment.