I'm trying to configure my django rest API to authenticate using google sign in OAuth and django-rest-framework-social-oauth2
I've already seen this question but I can't seem to figure out how they retrieved the access_token
What I have tried this far following this guide:
Started a new project in console.developers.google.com
Added to settings.py
:
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '2377[...].apps.googleusercontent.com'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '[...]'
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = ['email']
INSTALLED_APPS = [
...
# oauth
'oauth2_provider',
'social_django',
'rest_framework_social_oauth2'
]
AUTHENTICATION_BACKENDS = (
# Google OAuth2
'social_core.backends.google.GoogleOAuth2',
# django-rest-framework-social-oauth2
'rest_framework_social_oauth2.backends.DjangoOAuth2',
# Django
'django.contrib.auth.backends.ModelBackend',
)
But when I try to exchange my Auth Code, which I got from Google Sign In on Android
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode(Values.CLIENT_ID_WEB_APP)
.requestEmail()
.build();
for an access token in my Django Rest API backend using
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new FormEncodingBuilder()
.add("grant_type", "convert_token")
.add("client_id", Values.CLIENT_ID_REST_APP)
.add("client_secret", Values.CLIENT_SECRET_REST_APP)
.add("backend", "google-oauth2")
.add("token", idToken)
.build();
I get a 400 HTTP response from server:
{"error":"access_denied","error_description":"Your credentials aren't allowed"}
Am I missing something? Thanks in advance!