refactored social auth
This commit is contained in:
parent
3b7bef463f
commit
442e4fb2ce
|
|
@ -1,4 +1,6 @@
|
|||
"""Common views for application Account"""
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
|
||||
from braces.views import CsrfExemptMixin
|
||||
|
|
@ -30,12 +32,12 @@ from utils.views import JWTGenericViewMixin
|
|||
# OAuth2
|
||||
class BaseOAuth2ViewMixin(generics.GenericAPIView):
|
||||
"""BaseMixin for classic auth views"""
|
||||
@property
|
||||
def client_credentials(self) -> dict:
|
||||
"""Get application credentials."""
|
||||
|
||||
def get_client_credentials(self, source) -> dict:
|
||||
"""Get application credentials by source."""
|
||||
credentials = {}
|
||||
qs = Application.objects.filter(authorization_grant_type=Application.GRANT_PASSWORD,
|
||||
client_type=Application.CLIENT_CONFIDENTIAL)
|
||||
source=source)
|
||||
if qs.exists():
|
||||
application = qs.first()
|
||||
credentials = dict(client_id=application.client_id,
|
||||
|
|
@ -51,15 +53,22 @@ class OAuth2ViewMixin(CsrfExemptMixin, OAuthLibMixin, BaseOAuth2ViewMixin):
|
|||
|
||||
def prepare_request_data(self, validated_data: dict) -> dict:
|
||||
"""Preparing request data"""
|
||||
client_id = self.client_credentials.get('client_id')
|
||||
client_secret = self.client_credentials.get('client_secret')
|
||||
source = validated_data.get('source')
|
||||
credentials = self.get_client_credentials(source=source)
|
||||
|
||||
client_id = credentials.get('client_id')
|
||||
client_secret = credentials.get('client_secret')
|
||||
token = validated_data.get('token')
|
||||
appsecret_proof = hmac.new(settings.SOCIAL_AUTH_FACEBOOK_KEY.encode('utf-8'),
|
||||
msg=settings.SOCIAL_AUTH_FACEBOOK_SECRET.encode('utf-8'),
|
||||
digestmod=hashlib.sha256).hexdigest()
|
||||
|
||||
if client_id and client_secret and token:
|
||||
return {
|
||||
'client_id': client_id,
|
||||
'client_secret': client_secret,
|
||||
'token': token
|
||||
'token': token,
|
||||
'appsecret_proof': appsecret_proof,
|
||||
}
|
||||
else:
|
||||
raise utils_exceptions.ServiceError(data={
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user