Authkestra

Google

Integrate Google OAuth2 authentication with OpenID Connect support.

Setup Guide

1. Create Google OAuth Credentials

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Navigate to APIs & Services → Credentials
  4. Click Create Credentials → OAuth client ID
  5. Select Web application
  6. Add authorized redirect URI: http://localhost:3000/auth/google/callback
  7. Copy the Client ID and Client Secret

OAuth Consent Screen

You'll need to configure the OAuth consent screen before creating credentials. For development, you can use "External" type and add yourself as a test user.

2. Configure Environment

.env
AUTHKESTRA_GOOGLE_CLIENT_ID=your_client_id.apps.googleusercontent.com
AUTHKESTRA_GOOGLE_CLIENT_SECRET=your_client_secret
AUTHKESTRA_GOOGLE_REDIRECT_URI=http://localhost:3000/auth/google/callback

Implementation

use authkestra_flow::OAuth2Flow;
use authkestra_providers_google::GoogleProvider;

// Create the Google provider
let provider = GoogleProvider::new(
    std::env::var("AUTHKESTRA_GOOGLE_CLIENT_ID").unwrap(),
    std::env::var("AUTHKESTRA_GOOGLE_CLIENT_SECRET").unwrap(),
    std::env::var("AUTHKESTRA_GOOGLE_REDIRECT_URI")
        .unwrap_or_else(|_| "http://localhost:3000/auth/google/callback".to_string()),
);

// Add to Authkestra
let authkestra = Authkestra::builder()
    .provider(OAuth2Flow::new(provider))
    .build();

Available Scopes

ScopeDescription
openidOpenID Connect identity (default)
emailUser's email address
profileBasic profile info (name, picture)
// Request specific scopes
let flow = OAuth2Flow::new(provider)
    .with_scopes(vec!["openid", "email", "profile"]);

Identity Attributes

Google provider populates these attributes:

// Google provider populates these attributes
let picture = identity.attributes.get("picture");  // Profile photo URL
let given_name = identity.attributes.get("given_name");
let family_name = identity.attributes.get("family_name");
let locale = identity.attributes.get("locale");
let verified_email = identity.attributes.get("verified_email");

On this page