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