Auth provider

From tinh2/skills-hub-registry · View interactive version

Auth provider is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Set up complete OAuth/SSO authentication with Google, GitHub, Apple, or SAML providers. Triggers: you need OAuth login, social sign-in, SSO integration, authentication setup, login page.

How to use this skill

Skill file

You are in AUTONOMOUS MODE. Do NOT ask questions. Execute the full pipeline below

without pausing for user input. Make reasonable decisions using sensible defaults.

PURPOSE:

Set up a complete authentication system with OAuth/SSO providers in the current project.

This includes SDK installation, provider configuration, session management, token refresh,

login/logout UI, and route protection.

INPUT:

$ARGUMENTS

The user may specify:

  1. Providers: "google", "github", "apple", "saml", or a combination (e.g., "google github")
  2. Auth library preference: "nextauth", "passport", "firebase", "supabase", "clerk", "lucia"
  3. Session strategy: "jwt" (default) or "database"

If no arguments, default to Google + GitHub providers with the best-fit auth library.

=== PHASE 1: PROJECT DETECTION ===

Step 1.1 -- Detect Framework and Existing Auth

Scan for project files to determine the tech stack:

| File | Framework | Recommended Auth Library |

|------|-----------|------------------------|

| package.json with "next" | Next.js | NextAuth.js (Auth.js v5) |

| package.json with "fastify" | Fastify | @fastify/oauth2 + custom JWT |

| package.json with "express" | Express | Passport.js |

| package.json with "nestjs" | NestJS | @nestjs/passport |

| package.json with "hono" | Hono | Custom JWT + OAuth |

| requirements.txt with "django" | Django | django-allauth |

| requirements.txt with "fastapi" | FastAPI | authlib + python-jose |

| Gemfile with "rails" | Rails | devise + omniauth |

| pubspec.yaml with "firebase_auth" | Flutter | Firebase Auth |

| pubspec.yaml (no firebase) | Flutter | Supabase Auth or custom |

Check for existing auth:

Record: FRAMEWORK, AUTH_LIBRARY (user-specified or auto-detected), EXISTING_AUTH

If a complete auth system already exists, report it and exit.

If partial auth exists, identify gaps and extend it.

Step 1.2 -- Parse Provider Requirements

From $ARGUMENTS, extract which providers to configure:

Record: PROVIDERS list

=== PHASE 2: AUTH LIBRARY INSTALLATION ===

Step 2.1 -- Install Auth Library

Based on the detected or specified auth library:

NextAuth.js (Auth.js v5) -- for Next.js:

npm install next-auth@beta @auth/prisma-adapter  (if using Prisma)
npm install next-auth@beta @auth/drizzle-adapter  (if using Drizzle)

Passport.js -- for Express/Fastify/NestJS:

npm install passport passport-google-oauth20 passport-github2
npm install express-session connect-pg-simple  (for database sessions)
npm install jsonwebtoken @types/jsonwebtoken  (for JWT strategy)

Firebase Auth -- for Flutter or web apps using Firebase:

flutter pub add firebase_auth google_sign_in  (Flutter)
npm install firebase-admin  (backend verification)

Supabase Auth -- for Supabase projects:

npm install @supabase/supabase-js @supabase/auth-helpers-nextjs
flutter pub add supabase_flutter  (Flutter)

django-allauth -- for Django:

pip install django-allauth

Lucia -- for any Node.js framework:

npm install lucia @lucia-auth/adapter-prisma  (or appropriate adapter)
npm install arctic  (for OAuth helpers)

Install only the packages needed for the detected framework and requested providers.

Step 2.2 -- Configure Environment Variables

Add to .env.example:

# Auth
AUTH_SECRET=<random-32-char-string>
AUTH_URL=http://localhost:3000  (or appropriate base URL)

# Google OAuth (if requested)
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

# GitHub OAuth (if requested)
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

# Apple Sign-In (if requested)
APPLE_CLIENT_ID=
APPLE_CLIENT_SECRET=
APPLE_TEAM_ID=
APPLE_KEY_ID=

If the project has a config validation system, update it with the new variables.

=== PHASE 3: AUTH CONFIGURATION ===

Step 3.1 -- Create Auth Configuration Module

Create the central auth configuration at the framework-appropriate location:

NextAuth.js:

Passport.js:

Firebase Auth:

Lucia:

For EACH requested provider, configure:

  1. Client ID and Client secret from environment variables
  2. Callback URL (construct from AUTH_URL + provider-specific path)
  3. Requested scopes (email, profile as minimum; additional based on needs)
  4. Profile mapping (map provider profile to your User model)

Step 3.2 -- Database Schema Updates

If the project uses a database, create or update the auth-related tables:

For Prisma (schema.prisma):

model User {
  id            String    @id @default(cuid())
  email         String    @unique
  name          String?
  image         String?
  emailVerified DateTime?
  accounts      Account[]
  sessions      Session[]
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
}

model Account {
  id                String  @id @default(cuid())
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?
  access_token      String?
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?
  user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)
  @@unique([provider, providerAccountId])
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       String
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

Run the migration after schema changes: npx prisma migrate dev --name add-auth-tables

For other ORMs, create equivalent migrations.

If the project is Flutter + Firebase, skip database schema -- Firebase Auth manages this.

Step 3.3 -- Session Management

Configure session handling based on the strategy:

JWT Strategy (default for most setups):

Database Session Strategy:

Token Refresh Flow:

=== PHASE 4: AUTH MIDDLEWARE ===

Step 4.1 -- Create Auth Middleware

Create middleware that can protect routes/pages:

For API routes:

For Next.js:

For Flutter:

Step 4.2 -- Create Auth Helper Functions

Create utility functions:

getCurrentUser(request):
  - Extract and verify the token from the request
  - Return the user object or null

requireAuth(request):
  - Same as getCurrentUser but throws 401 if not authenticated

requireRole(request, role):
  - Same as requireAuth but also checks user role
  - Throws 403 if insufficient permissions

isAuthenticated(request):
  - Returns boolean -- does not throw

=== PHASE 5: LOGIN/LOGOUT UI ===

Step 5.1 -- Create Login Page/Screen

For Next.js / React:

Create a login page with:

For Flutter:

Create a login screen with:

For API-only backends (no frontend):

Step 5.2 -- Create Logout Flow

Create logout functionality:

Step 5.3 -- Create Auth State UI Components

Create reusable auth-aware components:

=== PHASE 6: ROUTE PROTECTION ===

Step 6.1 -- Protect Existing Routes

Scan the project for routes/pages that should be protected:

Apply the auth middleware to these routes.

Step 6.2 -- Create Auth Callback Routes

For each provider, ensure the callback route is configured:

These must match the redirect URIs configured in the provider's developer console.

=== PHASE 7: VERIFICATION ===

Step 7.1 -- Static Verification

Run the project's type checker and linter:

Step 7.2 -- Auth Flow Checklist

Verify and report:

=== OUTPUT ===

Print the following summary:


Auth Integration Complete

Framework: [detected framework]

Auth library: [library used]

Providers: [list of configured providers]

Session strategy: [JWT | database]

Files Created/Modified

| File | Purpose |

|------|---------|

| [path] | [description] |

Environment Variables Required

| Variable | Purpose | Where to get it |

|----------|---------|-----------------|

| AUTH_SECRET | Session encryption | Generate: openssl rand -base64 32 |

| GOOGLE_CLIENT_ID | Google OAuth | Google Cloud Console > Credentials |

| GOOGLE_CLIENT_SECRET | Google OAuth | Google Cloud Console > Credentials |

| GITHUB_CLIENT_ID | GitHub OAuth | GitHub Settings > Developer > OAuth Apps |

| GITHUB_CLIENT_SECRET | GitHub OAuth | GitHub Settings > Developer > OAuth Apps |

OAuth Callback URLs to Register

| Provider | Callback URL |

|----------|-------------|

| Google | http://localhost:3000/api/auth/callback/google |

| GitHub | http://localhost:3000/api/auth/callback/github |

Protected Routes

[List of routes that now require authentication]

Provider Setup Instructions

Google:

  1. Go to Google Cloud Console > APIs & Services > Credentials
  2. Create OAuth 2.0 Client ID (Web application)
  3. Add authorized redirect URI: [callback URL]
  4. Copy Client ID and Secret to .env

GitHub:

  1. Go to GitHub Settings > Developer Settings > OAuth Apps
  2. Create a new OAuth App
  3. Set Authorization callback URL: [callback URL]
  4. Copy Client ID and Secret to .env

=== NEXT STEPS ===

After auth integration:

=== DO NOT ===

============================================================

SELF-HEALING VALIDATION (max 3 iterations)

============================================================

After completing the integration, validate:

  1. Run the project's test suite to verify the integration works end-to-end.
  2. Run build/compile to confirm no breakage.
  3. Verify the integration responds correctly (health checks, test calls, smoke tests).
  4. If failures occur, diagnose from error output and apply minimal fixes.
  5. Repeat up to 3 iterations.

IF STILL FAILING after 3 iterations:

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /auth-provider — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.