Stack Exchange
Google OAUTH2: error_description: 'Invalid client_id parameter value with 400 error
this is my login.jsx
import axios from "axios";
import {Navigate} from "react-router-dom";
import {useState} from "react";
import GoogleLogin from "react-google-login";
import {gapi} from "gapi-script";
import {useEffect} from "react";
import 'bootstrap/dist/css/bootstrap.css';

    export const Login = () => {
    const clientId = "252855945185-0fm1oqq2945rkv2sak6satjgvopiiv1o.apps.googleusercontent.com";
      const onSuccess = async (res) => {

        console.log('succzddgsfgess:', res.accessToken);
        const user = {
              "grant_type":"convert_token",
              "client_id":"",       // <==== replace with google client_id from google console
              "client_secret":"",   // <==== replace with google client_secret from google console
              "backend":"google",
              "token": res.accessToken
            };
            console.log("hi")
            console.log(user)
            const {data} = await axios.post('http://localhost:8000/api-auth/convert-token/', user ,{headers: {
                'Content-Type': 'application/json'
            }}, {withCredentials: true}); <=== where error caused

            console.log('API Response:', data);


            console.log(data, data['access_token'])
            axios.defaults.headers.common['Authorization'] = `Bearer ${data['access_token']}`;
            localStorage.clear();
            localStorage.setItem('access_token', data.access_token);
            localStorage.setItem('refresh_token', data.refresh_token);
            try{
              window.location.href = '/'
            }catch(error){
              console.error("error", error);
            }
      }

      const onFailure = (err) => {
        console.log('failed:', err);
      };

    return(
        <div className="Auth-form-container">
          <GoogleLogin
            clientId={clientId}
            buttonText="Sign in with Google"
            onSuccess={onSuccess}
            onFailure={onFailure}
            cookiePolicy={'single_host_origin'}
            
        />
        </div>

    )
}

this is my settings.py
"""
Django settings for config project.

Generated by 'django-admin startproject' using Django 4.2.7.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-$$8)opv-#e4^kz#hzuu!52v6u0!+iu@w7hti4bhi&csz-avf**'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    #   adding rest api and api app
    'rest_framework',
    'api.apps.ApiConfig',
    # 'cordsheaders'
    'corsheaders',
    #   login feature
    'oauth2_provider',
    'social_django',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    #adding
    'corsheaders.middleware.CorsMiddleware',
]

ROOT_URLCONF = 'config.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]
# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.postgresql',
#         'NAME': 'genventory',
#         'USER': 'admin',
#         'PASSWORD': 'utah123',
#         'HOST': 'localhost',
#         'PORT': '',
#     }
# }

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = 'static/'
STATIC_ROOT = 'static/'

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

#   login feature

CORS_ORIGIN_ALLOW_ALL = True

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
        'drf_social_oauth2.authentication.SocialAuthentication',
    ),
}

AUTHENTICATION_BACKENDS = (
    # Google OAuth2
   'social_core.backends.google.GoogleOAuth2',
   'drf_social_oauth2.backends.DjangoOAuth2',
   'django.contrib.auth.backends.ModelBackend',
    'rest_framework_social_oauth2.backends.DjangoOAuth2',

)


# Define SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE to get extra permissions from Google.
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/userinfo.profile',
]
#   google configuration
# SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = <Google client id> <== I replaced it with google clinet id 
# SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = <Google client secret> <== I replaced it with goolge client secret

WSGI_APPLICATION = 'config.wsgi.application'

this is my urls.py
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('api.urls')),
    #   login feature
    path('auth/', include('authentication.urls')),
    path('api-auth/', include('drf_social_oauth2.urls',namespace='drf')),
]

I am receiving a 400 error with the message 'Request failed with status code 400' because of an 'Invalid client_id parameter value' when I send a user to 'http://localhost:8000/api-auth/convert-token/'.
{
"error": "invalid_request",
"error_description": "Invalid client_id parameter value."
}
However, I can access 'http://localhost:8000/api-auth/convert-token/' without any issues...and I cannot find any problem with client_id parameter value since I replaced it with goolge client_id from google console -> credentials
Any suggestions would be greatly appreciated
