Aura Auth

OAuth Providers

Explore built-in OAuth providers and configure them in TypeScript applications with Aura Auth.

An OAuth provider is an external service that implements the OAuth 2.0 authorization framework. OAuth allows applications to obtain limited access to a user's resources without requiring the user to share their credentials directly with the application.

Aura Auth integrates with external providers to manage authorization flows and, where supported, retrieve user profile information. The provider handles user authentication and consent, while Aura Auth manages the corresponding authorization flow within the application.

For more information about the underlying protocol, see the OAuth 2.0 Authorization Framework.


Implementation Patterns

Aura Auth supports three ways to configure built-in OAuth providers, depending on the application's customization and bundle-size requirements.

String Pattern

The string pattern is the simplest way to enable a built-in provider. Pass the provider's identifier to the oauth array, and Aura Auth resolves the provider configuration using the corresponding environment variables.

@/lib/auth.ts
import { createAuth } from "@aura-stack/auth"

export const auth = createAuth({
  oauth: ["github"],
})

The string pattern does not support customizing individual provider options. To override defaults or configure additional options, use the provider factory or modular import pattern instead.

Provider Factories

The builtInOAuthProviders object provides a centralized collection of built-in provider factories. This pattern is useful when provider configurations need to be customized while keeping imports centralized.

@/lib/auth.ts
import { createAuth } from "@aura-stack/auth"
import { builtInOAuthProviders } from "@aura-stack/auth/oauth/index"

export const auth = createAuth({
  oauth: [
    builtInOAuthProviders.github({
      authorize: {
        url: "https://github.com/login/oauth/authorize",
        params: {
          scope: "read:user user:email repo",
        },
      },
    }),
  ],
})

Modular Imports

Modular imports load a provider directly from its dedicated entry point. This approach can help bundlers eliminate unused provider implementations through tree-shaking, making it useful when bundle size is a concern.

@/lib/auth.ts
import { createAuth } from "@aura-stack/auth"
import { github } from "@aura-stack/auth/oauth/github"

export const auth = createAuth({
  oauth: [
    github({
      authorize: {
        url: "https://github.com/login/oauth/authorize",
        params: {
          scope: "read:user user:email repo",
        },
      },
    }),
  ],
})

On this page