FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Getting error in Google Oauth integration

    Scheduled Pinned Locked Moved Unsolved
    Q&A
    3
    5
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      prince.b
      last edited by

      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}`
      
      1 Reply Last reply Reply Quote 0
      • mark.robustelliM
        mark.robustelli
        last edited by

        Are you trying to allow the user to log into your application using Google?

        1 Reply Last reply Reply Quote 0
        • P
          prince.b
          last edited by

          @mark-robustelli Yes, im trying to do the same.

          mark.robustelliM 1 Reply Last reply Reply Quote 0
          • mark.robustelliM
            mark.robustelli @prince.b
            last edited by

            @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.

            Screenshot 2024-02-15 at 8.41.19 AM.png

            1 Reply Last reply Reply Quote 0
            • S
              SabrinaC
              last edited by

              Are you attempting to enable users to log into your application using Google? Click Here for further details

              1 Reply Last reply Reply Quote 0
              • First post
                Last post