Authentication And Security

Enable your Webflow users to log in with Google using Xano (OAuth2)

In this guide, we'll walk you through the process of setting up OAuth authentication with Google for your Webflow site using Xano, a no-code backend platform. By following these steps, you'll be able to allow your users to sign in with their Google accounts, enhancing the user experience and streamlining the authentication process.

Understanding OAuth

Before we dive into the setup process, let's briefly explain what OAuth is and why it's important.

OAuth (Open Authorization) is a standard protocol that allows users to grant third-party applications access to their resources hosted on other services without sharing their credentials. In simpler terms, it enables you to log in to an application using your existing accounts from services like Google, Facebook, Twitter, etc.

This approach has several benefits:

  1. Simplified Login Process: Users don't have to create and manage a new set of credentials for every application they use.
  2. Improved Security: Users don't have to share their sensitive login credentials with third-party applications.
  3. Increased Convenience: Users can access multiple applications with a single sign-on experience.

Setting Up OAuth with Xano

Xano is a no-code platform that simplifies backend development, including authentication and authorization. Let's get started by setting up OAuth with Google in Xano.

  1. Create a Xano Account: If you haven't already, create a free Xano account at https://xano.io.

  2. Create a New Workspace: After logging in, create a new workspace by clicking the "Create New Workspace" button. Give your workspace a name (e.g., "OAuth Webflow Demo").

  3. Configure User Authentication: During the workspace setup process, Xano will ask you how your users will log in. Select the "Google" option to enable Google OAuth authentication.

  4. Configure Google OAuth Credentials: After completing the workspace setup, Xano will prompt you to configure your Google OAuth credentials. Follow the instructions provided by Xano, which will guide you through the process of creating a new Google Cloud Platform project and obtaining the necessary client ID and client secret.

  • Visit the Google Cloud Console and create a new project.
  • Enable the Google+ API for your project.
  • Configure the OAuth consent screen by providing your app's name and authorized domains (e.g., Webflow.com).
  • Create an OAuth client ID for a web application and specify the authorized redirect URI (we'll provide this later when setting up Webflow).
  • Copy the client ID and client secret provided by Google and paste them into Xano's configuration screen.
  1. Update Xano: After entering your Google OAuth credentials, click "Update" in Xano to save the configuration.

Xano has now set up the necessary backend infrastructure for Google OAuth authentication, including API endpoints for initializing, continuing, logging in, and signing up users.

Integrating OAuth with Webflow

Next, we'll integrate the OAuth flow into your Webflow site using JavaScript.

  1. Create Webflow Pages: In your Webflow project, create two pages: login and my-account. The login page will contain a "Continue with Google" button, and the my-account page will display the user's information after successful authentication.

  2. Add JavaScript Code: Copy the provided JavaScript code (available in the video description or the comments section) and paste it into the <script> tags at the bottom of both the login and my-account pages.

  3. Update JavaScript Variables: In the JavaScript code, update the following variables with the appropriate values:

  • loginPath: The path to your login page in Webflow (e.g., /oauth/login).
  • redirectURI: The full URL of your my-account page in Webflow (e.g., https://your-project-id.webflow.io/oauth/my-account). This should match the authorized redirect URI you configured in Google Cloud Platform.
  • oauthInitURL: The Xano API endpoint for initializing the OAuth flow (e.g., https://YOUR_XANO_WORKSPACE_ID.xano.io/api/google-oauth/init).
  • continueURL: The Xano API endpoint for continuing the OAuth flow (e.g., https://YOUR_XANO_WORKSPACE_ID.xano.io/api/google-oauth/continue).
  1. Update Webflow Elements: In the my-account page, add HTML elements with the IDs email and name. The JavaScript code will populate these elements with the user's email and name after successful authentication.

  2. Add a Logout Button: On the my-account page, add a button or link with the ID logout. When clicked, this button will log the user out by clearing the authentication token from local storage.

  3. Publish Your Webflow Site: Once you've made all the necessary changes, publish your Webflow site to make it live.

Testing the OAuth Flow

After completing the setup, you can test the OAuth flow by visiting your published Webflow site.

  1. Navigate to the login page and click the "Continue with Google" button.
  2. You'll be prompted to select a Google account to authenticate with.
  3. After granting the necessary permissions, you'll be redirected to the my-account page, where your email and name will be displayed.
  4. To log out, click the "Logout" button or link.

Congratulations! You've successfully implemented OAuth authentication with Google for your Webflow site using Xano as the backend platform.

Remember, while this guide focused on Google OAuth, the principles and techniques can be applied to other OAuth providers as well, such as Facebook, Twitter, or GitHub, by updating the appropriate credentials and API endpoints in Xano and the JavaScript code.

Sign up for Xano

Join 100,000+ people already building with Xano.

Start today and scale to millions.

Start building for free