From 8651252ce5e93446601c492ddef5eb35ee02bc42 Mon Sep 17 00:00:00 2001 From: Hamidreza Date: Thu, 12 Dec 2019 14:16:20 +0330 Subject: [PATCH 1/2] already registered emails bug fixed --- rest_framework_social_oauth2/oauth2_grants.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rest_framework_social_oauth2/oauth2_grants.py b/rest_framework_social_oauth2/oauth2_grants.py index ebbc9c5..57e30fb 100644 --- a/rest_framework_social_oauth2/oauth2_grants.py +++ b/rest_framework_social_oauth2/oauth2_grants.py @@ -5,6 +5,7 @@ except ImportError: # Will be removed in Django 2.0 from django.core.urlresolvers import reverse +from django.db import IntegrityError from oauthlib.oauth2.rfc6749 import errors from oauthlib.oauth2.rfc6749.grant_types.refresh_token import RefreshTokenGrant @@ -97,6 +98,13 @@ def validate_token_request(self, request): request=request) except SocialAuthBaseException as e: raise errors.AccessDeniedError(description=str(e), request=request) + except IntegrityError as e: + e_msg = e.args[0][e.args[0].find('(email)'):]\ + .replace('(', ' ').replace(')', ' ').replace(' =', ':')\ + .replace('exists', 'registered').strip() + raise errors.CustomOAuth2Error(error='invalid_email_address', + status_code=400, + description=e_msg) if not user: raise errors.InvalidGrantError('Invalid credentials given.', request=request) From 5526bc0842cdea9eb19b9cedddf2e50171bd33b3 Mon Sep 17 00:00:00 2001 From: Hamidreza Ahmadi Date: Thu, 12 Dec 2019 16:33:54 +0330 Subject: [PATCH 2/2] change status_code form 400 to 409! --- rest_framework_social_oauth2/oauth2_grants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework_social_oauth2/oauth2_grants.py b/rest_framework_social_oauth2/oauth2_grants.py index 57e30fb..fe6f8e6 100644 --- a/rest_framework_social_oauth2/oauth2_grants.py +++ b/rest_framework_social_oauth2/oauth2_grants.py @@ -103,7 +103,7 @@ def validate_token_request(self, request): .replace('(', ' ').replace(')', ' ').replace(' =', ':')\ .replace('exists', 'registered').strip() raise errors.CustomOAuth2Error(error='invalid_email_address', - status_code=400, + status_code=409, description=e_msg) if not user: