bolt-lightningQuickstart: Stack Auth

Integrate GL IAM with Stack Auth for modern, managed authentication.

circle-info

When to use Stack Auth: Choose Stack Auth when you want managed authentication with minimal infrastructure, modern UI components, or need features like social login and MFA out of the box.

circle-info

What you'll build: A FastAPI application that authenticates users via Stack Auth tokens and enforces role-based access control using GL IAM's unified interface.

chevron-rightPrerequisiteshashtag

This example requires completion of all setup steps listed on the Prerequisites page. To summarize:

  • Python 3.11+

  • Access to the GDP Labs' Gen AI SDK repository (request via formarrow-up-right or ticket@gdplabs.id)

  • gcloud CLI: Installarrow-up-right, then run gcloud auth login

  • uvarrow-up-right — Install with: curl -LsSf https://astral.sh/uv/install.sh | sh

  • A Stack Auth project (cloud or self-hosted)

  • Stack Auth API keys (Project ID, Publishable Key, Secret Server Key)

Setup Stack Auth

  1. Create a new project

  2. Note your credentials:

    • Project ID (e.g., your-project-id)

    • Publishable Client Key (e.g., pck_...)

    • Secret Server Key (e.g., ssk_...)

Installation

Install GL IAM from the internal Google Artifact Registry (latest version).

5-Line Core

The essential code to validate Stack Auth tokens with GL IAM:

Step-by-Step

1

Configure Environment

Create .env file:

2

Setup Provider

3

Add Protected Endpoints

4

Run the Server

Output:

5

Test the API

circle-check

Complete Example

Create main.py:

Run it:

Getting Access Tokens

Stack Auth tokens are typically obtained through the frontend SDK:

Stack Auth Role Mapping

Stack Auth team permissions map to GL IAM standard roles:

Stack Auth Permission
GL IAM Standard Role
Access Level

team_admin

ORG_ADMIN

Admin endpoints

team_member

ORG_MEMBER

Member endpoints

circle-exclamation

Common Pitfalls

Pitfall
Solution

Token validation fails

Ensure secret_server_key is set correctly

User has no roles

User must be added to a team with permissions assigned

Wrong base URL

Use https://api.stack-auth.com for cloud, http://localhost:8102 for self-hosted

CORS issues in frontend

Configure allowed origins in Stack Auth dashboard

Last updated

Was this helpful?