# Use your own OAuth app for Google sign-in

> Use your own Google OAuth client ID and secret in thelastapi to show your company's name and branding on the Google sign-in consent screen.

**To use your own OAuth app for Google sign-in, get your environment's callback URL from `vibiz auth`, create a web client ID in Google Cloud, and run `vibiz auth providers add google --own --client-id <id>`.** Your own credentials display your business name, domain, and logo on Google's consent screen instead of shared platform defaults. You can configure your credentials independently for production and development, protecting your production users while testing locally.

If you want to start without setting up a Google Cloud project, you can [add Google sign-in without your own OAuth app](https://thelastapi.dev/blog/add-google-sign-in) using shared keys. When you want full control over your branding and verification, switch to your own client credentials by following this guide.

## Shared keys versus your own Google OAuth app

Every thelastapi project with the `auth` resource supports Google sign-in out of the box. You have two ways to configure it:

| Feature | Shared credentials | Your own Google OAuth app |
| --- | --- | --- |
| Setup step | Run `vibiz auth providers add google` | Create credentials in Google Cloud, then supply ID and secret |
| Consent screen brand | thelastapi default | Your business name, logo, and terms links |
| Who can configure in production | Full-access key or console owner | Full-access key or console owner |
| Agent configuration in development | Yes (`vibiz_auth_settings`) | No (secrets require human input via prompt or console) |
| Environment separation | Works immediately in both environments | Recommended: separate Google client IDs for dev and prod |

Shared keys are ideal for prototypes and internal tools. For customer-facing SaaS products, using your own Google client ID ensures your users see your own brand name when authorizing access.

## Where to find your callback URL

Before configuring credentials in Google Cloud, you need the authorized redirect URI that Google sends tokens back to. 

To view your project's sign-in settings and callback URLs, run:

```bash
vibiz auth --json
```

For your local development environment, pass the `--dev` flag:

```bash
vibiz auth --dev --json
```

The output contains the `callback_url` for Google in that environment. It also includes an `available_providers` object that lists the steps and destination URLs for provider consoles. 

Production and development environments each maintain their own sign-in service and callback URLs. The development environment trusts `http://localhost:3000` only, while production trusts the custom domains assigned to your project.

## How to create your Google OAuth client ID and secret

To generate your credentials:

1. Go to the Google Cloud console and select or create your Google Cloud project.
2. Navigate to **APIs & Services** > **OAuth consent screen**.
3. Choose **External** (or **Internal** if restricted to Google Workspace users in your organization) and click **Create**.
4. Enter your app name, user support email, and developer contact email. Save and continue through the Scopes screen (the base sign-in flow uses standard openid, profile, and email scopes).
5. Navigate to **APIs & Services** > **Credentials**.
6. Click **Create Credentials** at the top and select **OAuth client ID**.
7. Set the application type to **Web application**.
8. In the **Authorized redirect URIs** section, add the exact `callback_url` obtained from `vibiz auth`.
9. Click **Create**. Google displays your **Client ID** and **Client secret**.

Keep this window open or save the secret securely. If you run multiple AI tools on Google Cloud, you can also [use your own Gemini API key or Google Cloud credits](https://thelastapi.dev/blog/use-your-own-gemini-key) alongside your sign-in configuration.

## How to add your Google credentials to the project

Once you have your Google client ID and client secret, add them to your project using the CLI or the console.

To configure your production environment:

```bash
vibiz auth providers add google --own --client-id 1234567890-abcdef.apps.googleusercontent.com
```

The CLI prompts you for the client secret with hidden input, preventing secrets from leaking into your shell history:

```text
Enter Google client secret: ********
```

Alternatively, you can provide the secret via the environment variable `GOOGLE_CLIENT_SECRET`:

```bash
GOOGLE_CLIENT_SECRET=GOCSPX-yourSecretKey vibiz auth providers add google --own --client-id 1234567890-abcdef.apps.googleusercontent.com
```

To configure your local development environment with separate test credentials, add the `--dev` flag:

```bash
vibiz auth providers add google --own --client-id 1234567890-devid.apps.googleusercontent.com --dev
```

If you manage your project over plain HTTP, update settings using the project's API:

```bash
curl -X PUT "https://thelastapi.dev/v1/projects/prj_123/auth/providers/google?env=development" \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H 'content-type: application/json' \
  -d '{
    "credentials": "own",
    "client_id": "1234567890-devid.apps.googleusercontent.com",
    "client_secret": "GOCSPX-devSecret"
  }'
```

When you inspect settings later with `vibiz auth`, client secrets are never returned. The API returns `has_client_secret: true` instead.

To remove your custom Google provider settings at any point, run:

```bash
vibiz auth providers rm google
```

## How environments and keys handle OAuth secrets

thelastapi strictly divides production access from automated developer tooling. Under the permissions model detailed in [Keys and environments](https://thelastapi.dev/docs/keys), API keys have two default access levels: Full access (`access: owner`) and Limited (`access: agent`).

- **Full-access keys** can configure production sign-in settings, connect live domains, and read environment values.
- **Limited keys** are restricted to the development environment. They can start local development branches, modify dev settings, and toggle shared-key providers.
- **Secrets require a human.** Neither production OAuth secrets nor SMTP passwords can be passed through AI agent prompts. If a Limited key attempts to update production sign-in settings, the API answers `403 forbidden` with `details.reason: "owner_only"` and provides a `details.console_url` where the account owner can finish the configuration.

If you collaborate with other developers or work with other identity providers, you can also [add GitHub sign-in to your app](https://thelastapi.dev/blog/add-github-sign-in) using a similar `--own` configuration.

## What to do if your app runs on a custom domain

When you deploy your application to production, Google sign-in works in concert with your verified domains.

If you host your frontend on thelastapi hosting or purchase a domain using `vibiz domains buy`, your domain is automatically verified and trusted by the sign-in service:

```bash
vibiz domains buy acme.com
vibiz domains use acme.com --project prj_123
```

As covered in the [Domains documentation](https://thelastapi.dev/docs/domains), bought domains have their DNS managed automatically. Sign-in and analytics accept visits from the apex domain and `www` immediately.

If your frontend is hosted outside thelastapi, you can [use one service](https://thelastapi.dev/docs/use-one) independently. Register your custom domain so the sign-in service accepts it:

```bash
vibiz domains add app.example.com --elsewhere
```

When added with a Limited key, sign-in trusts the external domain once you add the generated TXT record (`_vibiz.app.example.com`) and run:

```bash
vibiz domains verify app.example.com
```

An account owner can also confirm the domain directly in the console.

## Wiring sign-in in your frontend application

Once Google sign-in is enabled, your application reads the environment configuration through the `@vibiz/app` package or standard environment variables.

If you generated your project using the SaaS template (`vibiz init myapp --template nextjs-saas`), user sessions and sign-in routes are already wired under `/api/auth/*`. To learn how to structure your session validation and protected pages, read [how to add sign-in to a Next.js app](https://thelastapi.dev/blog/add-sign-in-nextjs-app).

For projects running on any server or container, load the environment variables at startup:

```ts
import { vibiz } from '@vibiz/app';

// Injects VIBIZ_AUTH_BASE_URL, VIBIZ_AUTH_COOKIE_SECRET, and DATABASE_URL
await vibiz.loadEnv();
```

Your server code can now read `process.env.VIBIZ_AUTH_BASE_URL` to route incoming OAuth flows, while the session cookie is encrypted using `process.env.VIBIZ_AUTH_COOKIE_SECRET`.

To explore all supported authentication methods, callback parameters, and session limits, see the official [Sign-in documentation](https://thelastapi.dev/docs/sign-in). You can also run `vibiz dev` to test your Google sign-in flow locally against an isolated database branch.

## Frequently asked questions

### Can I use shared Google keys in development and my own OAuth app in production?

Yes. You can keep shared keys in development by running `vibiz auth providers add google --dev` while applying your custom credentials to production with `vibiz auth providers add google --own --client-id <id>`.

### Where do I find the authorized redirect URI to add into Google Cloud?

Run `vibiz auth --json` (or `vibiz auth --dev --json` for local testing). The returned settings object includes the exact `callback_url` property you must paste into the Google Cloud credentials screen.

### Can an AI agent configure my production Google client secret?

No. AI agents using Limited keys receive a `403 owner_only` error when attempting to update production authentication settings; custom OAuth secrets must be entered by an account owner via the web console or interactive CLI prompt.

### How do I verify my custom domain so Google sign-in works outside thelastapi hosting?

Add the domain using `vibiz domains add app.example.com --elsewhere`, place the specified TXT verification record in your DNS provider, and run `vibiz domains verify app.example.com` (or have the account owner confirm it in the console).

---

Published 2026-11-15 · https://thelastapi.dev/blog/own-oauth-app-google-sign-in
