Getting error in Google Oauth integration
-
Hi there, im using fusion auth for my app. I've been using FA(fusion auth) for discord but now I want to have google login as well. For this, i've created a new identity provider inside FA.
I need access token from google and im using FA for this. Below is the code for it.
const response = await fetch( `${process.env.FUSIONAUTH_URL}/api/identity-provider/login`, { headers: { "Content-Type": "application/json", }, method: "POST", body: JSON.stringify({ applicationId: process.env.FUSIONAUTH_CLIENT_ID, identityProviderId: process.env.FUSIONAUTH_GOOGLE_PROVIDER_ID, data: { code: context.params.code, redirect_uri: context.provider.callbackUrl, }, }), } );
I'm getting error in event logs. Logs:
2/14/2024 11:22:31 AM Z Using code and redirect_uri with login method UseRedirect: 2/14/2024 11:22:31 AM Z Call the [https://oauth2.googleapis.com/token] endpoint. 2/14/2024 11:22:31 AM Z Endpoint returned status code [400] 2/14/2024 11:22:31 AM Z The response was not successful, see the error event log.
Request to the [https://oauth2.googleapis.com/token] endpoint failed. Status code [400] Error response is { "error" : "invalid_grant", "error_description" : "Missing code verifier." }
Could anyone help? I've tried multiple things none worked.
I've tried adding grant_type and code_verifier as query params to FA url, it didn't worked. Like this:const url = `${process.env.FUSIONAUTH_URL}/api/identity-provider/login?code_verifier=${context.checks.code_verifier}`
-
Are you trying to allow the user to log into your application using Google?
-
@mark-robustelli Yes, im trying to do the same.
-
@prince-b Ok, looks like based on the message "Using code and redirect_uri with login method UseRedirect" you may have the wrong "Login method" selected for your Identity Provider. Can you share how yours is set up? You may want to try and selecting the other methods to see if they work for you.
-
Are you attempting to enable users to log into your application using Google? Click Here for further details