OAuth (Google)

Let users sign in with their Google account. On first sign-in, a Koolbase user account is automatically created.

How it works

Koolbase handles the OAuth flow server-side. Your app opens a browser to the Google auth URL, the user authorises, and Google redirects back to your app with an auth code. Koolbase exchanges the code for a session token and returns it to your app.

1

Your app calls getGoogleAuthUrl() to get the OAuth redirect URL

2

Open the URL in a browser or WebView — user signs in with Google

3

Google redirects back to your app deep link with a code parameter

4

Your app calls signInWithGoogle(code) — Koolbase exchanges the code and returns a session

5

If no account exists for this Google email, one is created automatically

Setup

Before using Google OAuth, configure your Google Client ID in the Koolbase dashboard under Project → Settings → OAuth Providers.

Google Cloud Console

You need a Google OAuth 2.0 client ID from the Google Cloud Console. Set your Koolbase callback URL as an authorised redirect URI: https://api.koolbase.com/v1/sdk/auth/oauth/callback

Sign in with Google

lib/auth.dartDart
import 'package:url_launcher/url_launcher.dart';

// Step 1: Get the Google auth URL
final authUrl = await Koolbase.auth.getGoogleAuthUrl();

// Step 2: Open in browser
await launchUrl(Uri.parse(authUrl), mode: LaunchMode.externalApplication);

// Step 3: In your deep link handler, extract the code
// e.g. myapp://auth/callback?code=4/0AX4...
final code = Uri.parse(incomingLink).queryParameters['code'];

// Step 4: Exchange the code for a Koolbase session
final session = await Koolbase.auth.signInWithGoogle(code: code!);

print(session.user.email);   // user@gmail.com
print(session.user.verified); // true — Google emails are pre-verified

Account linking

If a user with the same email already exists (registered with email/password), signing in with Google will link the OAuth account to the existing user. The user can then sign in with either method.

Email matching

Account linking is based on email address. If a user registered with user@gmail.com via email/password, signing in with Google using the same Gmail address will link to that account — not create a duplicate.