> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hanko.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign in with Google

> Step-by-step guide to integrating Sign in with Google using Hanko. Enable secure authentication and seamless onboarding for your app's users.

<div class="hidden">
  **Hanko Google OAuth Integration Guide**:

  **About Hanko**:

  Hanko is a modern open source authentication solution and the fastest way you integrate passkeys, 2FA, SSO, and more—with full control over your data. Move between self-hosted and Hanko Cloud anytime. No lock-in. Just Auth how it should be: secure, user friendly, and fully yours.

  **What This Guide Covers**: This guide demonstrates how to integrate Google OAuth authentication with Hanko, allowing users to sign in using their Google accounts. You'll learn to set up a Google Cloud Console project, configure OAuth consent, and implement Google login in your application.

  **Key Technologies**:

  * OAuth 2.0 and OpenID Connect protocols
  * Google Cloud Console and Google Auth Platform
  * JWT (JSON Web Tokens) for secure session management
  * Google OAuth 2.0 authorization server
  * RESTful API integration

  **Prerequisites**:

  * Active Hanko Cloud account with a configured project
  * Google account for Cloud Console access
  * Basic understanding of OAuth 2.0 authentication flow
  * Frontend application ready for integration

  **Tasks You'll Complete**:

  * Create a Google Cloud Console project and configure OAuth consent
  * Set up OAuth 2.0 credentials and redirect URLs
  * Configure Google OAuth settings in Hanko Console
  * Implement Google authentication in your frontend application
  * Handle authentication success and error states
</div>

<Steps>
  <Step title="Obtain Google OAuth credentials">
    * First, obtain the redirect URL from the [Hanko Console](https://cloud.hanko.io/), as you'll need this for Google configuration.
      Sign in to the Hanko console and select your project. Navigate to 'Settings' in the left sidebar and then to 'Social connections'.
      Copy the 'Redirect URL'.

          <img src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/socialConnections.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=48573a115326a36fdd182e597b5e9d30" alt="Hanko Callback URL" width={500} data-path="images/oauth-providers/google/socialConnections.png" />

    * Verify that your allowed redirect URL is configured correctly for your application.
      Navigate to the 'URLs' tab in the left sidebar.
      Ensure that Allowed redirect URLs includes your App URL + '\*\*'.

          <img src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/google/allowedRedirectURL.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=1b3bc9c07baa2ef9ecd281d94717c9b1" alt="Hanko allowed redirect url" width={500} data-path="images/oauth-providers/google/allowedRedirectURL.png" />

    * Navigate to [Google Cloud Console](https://console.cloud.google.com/), sign in and click on 'Select a project' at the top left.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/one.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=9e8c42d5287d129ebe1154842d293cde" alt="Google settings option" width={500} data-path="images/oauth-providers/google/one.png" />

    * Select 'New Project' from the top right of modal.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/two.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=f003db9c8fca70cfde46b02f487b9249" alt="Google settings option" width={500} data-path="images/oauth-providers/google/two.png" />

    * Provide a 'Project name', if you want the project to be part of an organization, assign it using the 'Location' input and hit 'Create'

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/three.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=c3ec0c5201cdeac765c6e0d83dedf2fc" alt="Google settings option" width={500} data-path="images/oauth-providers/google/three.png" />

    * Type 'OAuth' in the search bar and choose 'OAuth consent screen' from the results.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/four.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=f915bdbca50da9998d33e794c21d9c61" alt="Google settings option" width={500} data-path="images/oauth-providers/google/four.png" />

    * Configure your Google Auth Platform by clicking 'Get started' to begin setup.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/googleAuthConfig.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=77cfc1af388541b42ea772c79a45a096" alt="Google auth configuration" width={500} data-path="images/oauth-providers/google/googleAuthConfig.png" />

    * Name your app and select a user support Email.
          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/google/configurationOne.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=8aba840e9ff44d083a24c045c0fb27ed" alt="Google App Information" width={500} data-path="images/oauth-providers/google/configurationOne.png" />

    * Select 'User Type' depending on your requirements
          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/google/configurationTwo.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=efb7812d97a33fb9b5dc4ee0e6d2fd86" alt="Google Project Audience" width={500} data-path="images/oauth-providers/google/configurationTwo.png" />

    * Navigate to 'Google Auth Platform' > 'Audience' and publish your app.
          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/google/Test%20Users.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=f82b3c48fb2ad4e37dcbbacf6af1afec" alt="Google test users" width={500} data-path="images/oauth-providers/google/Test Users.png" />

    * Click 'Clients' in the left sidebar, then click 'Create client'.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/createClient.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=e832d5721e53a92e2ae544eac3e24de3" alt="Create oauth client" width={500} data-path="images/oauth-providers/google/createClient.png" />

    * Select 'Web application' as the application type.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/ten.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=12c6f932c7b93d5d7d17fbd2f70e0321" alt="Google settings option" width={500} data-path="images/oauth-providers/google/ten.png" />

    * Choose a name and paste the Redirect URL (that you obtained from the Hanko console) as an 'Authorized redirect URI'.

          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/nDll7gWf2olRVk-k/images/oauth-providers/google/clientSetup.png?fit=max&auto=format&n=nDll7gWf2olRVk-k&q=85&s=78c75c15e4d1a00ed53d6a0b05c05edf" alt="Google auth client setup" width={500} data-path="images/oauth-providers/google/clientSetup.png" />

    * The Google console will display information about the OAuth client. Copy and save both the 'Client ID' and 'Client secret', as you'll need these in the next step.
          <img className="border-[1px] border-black rounded-[10px]" src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/twelve.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=aef9facc6200cf198ddcd5d68d14368b" alt="Google settings option" width={500} data-path="images/oauth-providers/google/twelve.png" />
  </Step>

  <Step title="Configure Google OAuth credentials with Hanko">
    * In the 'Social connections' section, select Google and enable its toggle switch.
    * Input the earlier noted 'Client ID' and 'Client Secret', then click 'Save'.

          <img src="https://mintcdn.com/hanko/djMPan_QCdoQzxwW/images/oauth-providers/google/thirteen.png?fit=max&auto=format&n=djMPan_QCdoQzxwW&q=85&s=0a91a64b85938d7c1a677a62bbd1d7d0" alt="Hanko Callback URL" width={500} height={500} data-path="images/oauth-providers/google/thirteen.png" />
  </Step>

  <Step title="Implement Sign in with Google in your frontend application">
    Whether you choose to use the pre-designed UI from the `@teamhanko/hanko-elements` package or opt for a custom UI with the `@teamhanko/hanko-frontend-sdk` will determine your approach to frontend integration.

    <Tabs>
      <Tab title="Hanko Elements">
        * Integrate the `<hanko-auth>` component from `hanko-elements` based on our frontend guides. If everything is good, the component will display a button for signing in with 'Google' in login view.

                  <Note>
                    Make sure to configure the page the web component is embedded on as your error redirect URL as well as an allowed redirect URL.
                  </Note>

          Post successful Google authentication, the backend sets a session cookie and errors during authentication are displayed within the component accordingly.
      </Tab>

      <Tab title="Hanko Frontend SDK">
        * For a custom UI, initialize third party sign-in using `@teamhanko/hanko-frontend-sdk`.

        * Create Hanko client instance and call `thirdParty.auth` with google as the provider.

          ```js theme={null}
          import { Hanko } from "@teamhanko/hanko-frontend-sdk";

          const hanko = new Hanko("<your_hanko_api_url>");

          async function signInWithGoogle() {
          try {
              await hanko.thirdParty.auth("google", "<your_redirect_url>");
          } catch (error) {
              // handle error
          }
          }
          ```

        * On successful authentication, the API redirects you to the given redirect URL. The URL query includes a one time token that must be exchanged for a JWT. Use the `token.validate` method on your client to validate the token:

          ```js theme={null}
          import { Hanko } from "@teamhanko/hanko-frontend-sdk";

          const hanko = new Hanko("<your_hanko_api_url>");

          async function onLoad() {
          try {
              await hanko.token.validate();
          } catch (error) {
              // handle error
          }

          // you should now have a JWT cookie set
          }
          ```

          On success, the API issues a JWT which is then set by the SDK as a cookie (hanko). All other SDK methods can now use the cookie to make authenticated requests to the API.
      </Tab>
    </Tabs>
  </Step>
</Steps>
