✔️Login with Google

This guide assumes that you have basic knowledge about OAuth 2.0 and Google Authentication.

Setup your brand's OAuth 2.0 credentials

The table ExternalAuthenticationProvider contains the OAuth 2.0 credentials. You need to enter your Google OAuth 2.0 credentials in this table.

There are several ways to add your information by using JFW Core or JFW API:

// This is an OAuth 2.0 credential example.
{
  "web": {
    "client_id": "YOUR_CLIENT_ID.apps.googleusercontent.com",
    "project_id": "YOUR_PROJECT_ID",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "YOUR_CLIENT_SECRET",
    "redirect_uris": ["YOUR_REDIRECT_URI"]
  }
}

Setup the callback endpoint

After handling the authentication for you, JFW will redirect you to a callback URL.

// This is a callback URL. You have to implement the API to handle the URL.
https://yourband.com/auth/callback?returnUrl=%2Fhome&username=your.user&authKey=xxx
// This is a pseudo-code in your application.
function handleAuthCallback(request)
    // Extract returnUrl, username, and authKey from query parameters
    returnUrl = request.query.returnUrl
    username = request.query.username
    authKey = request.query.authKey

    // Verify if the authKey is valid 
    if isValidAuthKey(authKey)
        // If valid, authenticate the user
        user = authenticateUser(username, authKey)
        if user is not null
            // Redirect to returnUrl if authentication is successful
            redirect(returnUrl)
        else
            // Handle authentication failure
            redirect("/login?error=authenticationFailed")
    else
        // Handle invalid authKey scenario
        redirect("/login?error=invalidAuthKey")

Get a Google login URL from JFW

Once you have completed the steps above, you can proceed with the following information:

  • brandUrl: your brand URL.

  • callbackUrl: the callback URL that you implemented in this step.

  • returnUrl: the relative path or URL that you want JFW to append to your callback URL.

Last updated

Was this helpful?