Choose Your Language

OAuth42 SDKs

Official SDKs for your favorite programming languages. Get started with OAuth42 authentication in minutes with our well-documented, type-safe libraries.

Quick Start

JavaScript / TypeScript (Next.js)

npm install @oauth42/next next-auth

// app/api/auth/[...nextauth]/route.ts
import { createAuth } from '@oauth42/next/server';

const { handlers } = createAuth({ cookiePrefix: 'oauth42-app' });
export const { GET, POST } = handlers;

// Redirect URI to register: http://localhost:3000/api/auth/callback/oauth42

For non-Next.js JS/TS apps, use any standard OIDC client library — see the JavaScript SDK page.

Swift

// Add to Package.swift
dependencies: [
    .package(url: "https://github.com/oauth42/oauth42-swift", from: "1.0.0")
]

import OAuth42Swift

let client = OAuth42Client(
    clientId: "your_client_id",
    redirectURI: "myapp://callback",
    issuer: "https://oauth42.com"
)

let authURL = try await client.buildAuthorizationURL()

Python (FastAPI)

pip install oauth42

from fastapi import FastAPI, Depends
from oauth42 import OAuth42AsyncClient, OAuth42User
from oauth42.middleware.fastapi import OAuth42Middleware, get_current_user

app = FastAPI()
client = OAuth42AsyncClient.from_env()  # reads OAUTH42_* env vars
app.add_middleware(OAuth42Middleware, client=client)

@app.get("/protected")
async def protected(user: OAuth42User = Depends(get_current_user)):
    return {"email": user.email}

PKCE, state, token exchange, and ID-token validation are handled by the middleware.

Common Features

🔐

PKCE Support

Built-in PKCE (S256) for enhanced security in public clients

🔄

Auto Token Refresh

Automatic token refresh before expiration

💾

Secure Storage

Platform-native secure storage for tokens

📝

TypeScript Types

Full type safety and IntelliSense support

Async/Await

Modern async patterns for all languages

📚

Rich Documentation

Comprehensive guides and API references

Need a Different Language?

Don't see an SDK for your language? You can use our REST API directly or let us know what language you'd like to see supported.