Securing Authentication logo

Securing Authentication

Community
ancoleman
securing-authentication

Authentication, authorization, and API security implementation. Use when building user systems, protecting APIs, or implementing access control. Covers OAuth 2.1/OIDC, JWT patterns, sessions, Passkeys/WebAuthn, RBAC/ABAC/ReBAC, policy engines (OPA, Casbin, SpiceDB), managed auth (Clerk, Auth0), self-hosted (Keycloak, Ory), and API security best practices.

Overview

Publisherancoleman
Repositoryai-design-components
Skill namesecuring-authentication
Stars
523
Forks
73
Bundled files
11
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 11 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by ancoleman on GitHub. Read the source before you install it.

Installation

Install the Securing Authentication AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ancoleman/ai-design-components.git /tmp/ai-design-components
mkdir -p .claude/skills
cp -r /tmp/ai-design-components/skills/securing-authentication .claude/skills/securing-authentication
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Securing Authentication in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Securing Authentication on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Securing Authentication is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Authentication & Security

Implement modern authentication, authorization, and API security across Python, Rust, Go, and TypeScript.

When to Use This Skill

Use this skill when:

  • Building user authentication systems (login, signup, SSO)
  • Implementing authorization (roles, permissions, access control)
  • Securing APIs (JWT validation, rate limiting)
  • Adding passwordless auth (Passkeys/WebAuthn)
  • Migrating from password-based to modern auth
  • Integrating enterprise SSO (SAML, OIDC)
  • Implementing fine-grained permissions (RBAC, ABAC, ReBAC)

OAuth 2.1 Mandatory Requirements (2025 Standard)

┌─────────────────────────────────────────────────────────────┐
│           OAuth 2.1 MANDATORY REQUIREMENTS                  │
│                   (RFC 9798 - 2025)                         │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ✅ REQUIRED (Breaking Changes from OAuth 2.0)             │
│  ├─ PKCE (Proof Key for Code Exchange) MANDATORY           │
│  │   └─ S256 method (SHA-256), minimum entropy 43 chars   │
│  ├─ Exact redirect URI matching                            │
│  │   └─ No wildcard matching, no substring matching       │
│  ├─ Authorization code flow ONLY for public clients       │
│  │   └─ All other flows require confidential client       │
│  └─ TLS 1.2+ required for all endpoints                   │
│                                                             │
│  ❌ REMOVED (No Longer Supported)                          │
│  ├─ Implicit grant (security vulnerabilities)             │
│  ├─ Resource Owner Password Credentials grant              │
│  │   └─ Use OAuth 2.0 Device Flow (RFC 8628) instead      │
│  └─ Bearer token in query parameters                       │
│      └─ Must use Authorization header or POST body        │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Critical: PKCE is now mandatory for ALL OAuth flows, not just public clients.

JWT Best Practices

Signing Algorithms (Priority Order)

  1. EdDSA with Ed25519 (Recommended)

    • Fastest performance
    • Smallest signature size
    • Modern cryptography
  2. ES256 (ECDSA with P-256)

    • Good performance
    • Industry standard
    • Wide compatibility
  3. RS256 (RSA)

    • Legacy compatibility
    • Larger signatures
    • Slower performance

NEVER allow alg: none or algorithm switching attacks.

Token Lifetimes (Concrete Values)

  • Access token: 5-15 minutes
  • Refresh token: 1-7 days with rotation
  • ID token: Same as access token (5-15 minutes)

Refresh token rotation: Each refresh generates new access AND refresh tokens, invalidating the old refresh token.

Token Storage

  • Access token: Memory only (never localStorage)
  • Refresh token: HTTP-only cookie + SameSite=Strict
  • CSRF token: Separate non-HTTP-only cookie
  • Never log tokens: Redact in application logs

JWT Claims (Required)

json
{
  "iss": "https://auth.example.com",
  "sub": "user-id-123",
  "aud": "api.example.com",
  "exp": 1234567890,
  "iat": 1234567890,
  "jti": "unique-token-id",
  "scope": "read:profile write:data"
}

Password Hashing with Argon2id

OWASP 2025 Parameters

Algorithm: Argon2id
Memory cost (m): 64 MB (65536 KiB)
Time cost (t): 3 iterations
Parallelism (p): 4 threads
Salt length: 16 bytes (128 bits)
Target hash time: 150-250ms

Implementation

For concrete implementations, see references/password-hashing.md.

Key Points:

  • Argon2id is hybrid: data-independent timing + memory-hard
  • Tune memory cost to achieve 150-250ms on YOUR hardware
  • Use timing-safe comparison for verification
  • Migrate from bcrypt gradually (verify with old, rehash with new)

Passkeys / WebAuthn

Passkeys provide phishing-resistant, passwordless authentication using FIDO2/WebAuthn.

When to Use Passkeys

  • User-facing applications prioritizing security
  • Reducing password-related support burden
  • Mobile-first applications (biometric auth)
  • Applications requiring MFA without SMS

Cross-Device Passkey Sync

  • iCloud Keychain: Apple ecosystem (iOS 16+, macOS 13+)
  • Google Password Manager: Android, Chrome
  • 1Password, Bitwarden: Third-party password managers

For implementation guide, see references/passkeys-webauthn.md.

Authorization Models

┌─────────────────────────────────────────────────────────────┐
│                Authorization Model Selection                │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  Simple Roles (<20 roles)                                  │
│  └─ RBAC with Casbin (embedded, any language)              │
│      Example: Admin, User, Guest                           │
│                                                             │
│  Complex Attribute Rules                                    │
│  └─ ABAC with OPA or Cerbos                                │
│      Example: "Allow if user.clearance >= doc.level        │
│                AND user.dept == doc.dept"                   │
│                                                             │
│  Relationship-Based (Multi-Tenant, Collaborative)          │
│  └─ ReBAC with SpiceDB (Zanzibar model)                    │
│      Example: "Can edit if member of doc's workspace       │
│                AND workspace.plan includes feature"         │
│      Use cases: Notion-like, GitHub-like permissions       │
│                                                             │
│  Kubernetes / Infrastructure Policies                       │
│  └─ OPA (Gatekeeper for admission control)                 │
│      Example: Enforce pod security policies                │
│                                                             │
└─────────────────────────────────────────────────────────────┘

For detailed comparison, see references/authorization-patterns.md.

Library Selection by Language

TypeScript

Use CaseLibraryContext7 IDTrustNotes
Auth FrameworkAuth.js v5/websites/authjs_dev87.4Multi-framework (Next, Svelte, Solid)
JWTjose 5.x--EdDSA, ES256, RS256 support
Passkeys@simplewebauthn/server 11.x--FIDO2 server
ValidationZod 3.x/colinhacks/zod90.4Schema validation
Policy EngineCasbin.js 1.x--RBAC/ABAC embedded

Python

Use CaseLibraryNotes
Auth FrameworkAuthlib 1.3+OAuth/OIDC client + server
JWTjoserfc 1.xModern, maintained
Passkeyspy_webauthn 2.xWebAuthn server
Password Hashingargon2-cffi 24.xOWASP parameters
ValidationPydantic 2.xFastAPI integration
Policy EnginePyCasbin 1.xRBAC/ABAC embedded

Rust

Use CaseLibraryNotes
JWTjsonwebtoken 10.xEdDSA, ES256, RS256
OAuth Clientoauth2 5.xOAuth 2.1 flows
Passkeyswebauthn-rs 0.5.xWebAuthn + attestation
Password Hashingargon2 0.5.xNative Argon2id
Policy EngineCasbin-RS 2.xRBAC/ABAC embedded

Go

Use CaseLibraryNotes
JWTgolang-jwt v5Community-maintained
OAuth Clientgo-oidc v3OIDC client only
Passkeysgo-webauthn 0.11.xDuo-maintained
Password Hashinggolang.org/x/crypto/argon2Standard library
Policy EngineCasbin v2Original implementation

Managed Auth Services

ServiceBest ForKey Features
ClerkRapid development, startupsPrebuilt UI, Next.js SDK
Auth0Enterprise, established25+ social providers, SSO
WorkOS AuthKitB2B SaaS, enterprise SSOSAML/SCIM, admin portal
Supabase AuthPostgres usersBuilt on Postgres, RLS

For detailed comparison, see references/managed-auth-comparison.md.

Self-Hosted Solutions

SolutionLanguageUse Case
KeycloakJavaEnterprise, on-prem
OryGoCloud-native, microservices
AuthentikPythonModern, developer-friendly

For setup guides, see references/self-hosted-auth.md.

API Security Best Practices

Rate Limiting

typescript
// Tiered rate limiting (per IP + per user)
const rateLimits = {
  anonymous: '10 requests/minute',
  authenticated: '100 requests/minute',
  premium: '1000 requests/minute',
}

Use sliding window algorithm (not fixed window) with Redis.

CORS Configuration

typescript
// Restrictive CORS (production)
const corsOptions = {
  origin: ['https://app.example.com'],
  credentials: true,
  maxAge: 86400, // 24 hours
  allowedHeaders: ['Content-Type', 'Authorization'],
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
}

// NEVER use origin: '*' with credentials: true

Security Headers

typescript
const securityHeaders = {
  'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload',
  'X-Frame-Options': 'DENY',
  'X-Content-Type-Options': 'nosniff',
  'Referrer-Policy': 'strict-origin-when-cross-origin',
  'Permissions-Policy': 'geolocation=(), microphone=(), camera=()',
  'Content-Security-Policy': "default-src 'self'; script-src 'self'",
}

For complete API security guide, see references/api-security.md.

Frontend Integration Patterns

Protected Routes (Next.js)

typescript
// middleware.ts
import { withAuth } from 'next-auth/middleware'

export default withAuth({
  callbacks: {
    authorized: ({ token, req }) => {
      if (req.nextUrl.pathname.startsWith('/dashboard')) {
        return !!token
      }
      if (req.nextUrl.pathname.startsWith('/admin')) {
        return token?.role === 'admin'
      }
      return true
    },
  },
})

export const config = {
  matcher: ['/dashboard/:path*', '/admin/:path*'],
}

Role-Based UI Rendering

typescript
import { useSession } from 'next-auth/react'

export function AdminPanel() {
  const { data: session } = useSession()

  if (session?.user?.role !== 'admin') {
    return null
  }

  return <div>Admin Controls</div>
}

Common Workflows

1. OAuth 2.1 Integration

  1. Generate PKCE challenge
  2. Redirect to authorization endpoint
  3. Handle callback with authorization code
  4. Exchange code for tokens (with code_verifier)
  5. Store tokens securely
  6. Implement refresh token rotation

See references/oauth21-guide.md for complete implementation.

2. JWT Implementation

  1. Generate signing keys using scripts/generate_jwt_keys.py
  2. Configure token lifetimes (5-15 min access, 1-7 day refresh)
  3. Implement token validation middleware
  4. Set up refresh token rotation
  5. Configure token storage (memory for access, HTTP-only cookie for refresh)

See references/jwt-best-practices.md for detailed patterns.

3. Passkeys Setup

  1. Register credential during signup/settings
  2. Generate challenge for registration
  3. Verify attestation
  4. Store credential ID and public key
  5. Implement authentication flow with assertion

See examples/passkeys-demo/ for runnable implementation.

4. Authorization Engine Setup

  1. Choose engine (Casbin for simple RBAC, SpiceDB for ReBAC)
  2. Define schema/policies
  3. Implement check functions
  4. Integrate with route handlers
  5. Add audit logging

See references/authorization-patterns.md for detailed comparison.

Integration with Other Skills

Forms Skill

  • Login/register forms with validation
  • Error states for auth failures
  • Password strength indicators
  • Email validation

API Patterns Skill

  • JWT middleware integration
  • Error response formats (401, 403)
  • OpenAPI security schemas
  • CORS configuration

Dashboards Skill

  • Role-based widget visibility
  • User profile display
  • Permission-based data filtering
  • Audit trail visualization

Observability Skill

  • Auth event logging (login, logout, permission denied)
  • Failed login tracking
  • Token refresh monitoring
  • Security incident alerting

Scripts

Generate JWT Keys

bash
python scripts/generate_jwt_keys.py --algorithm EdDSA

Generates EdDSA or ES256 key pairs for JWT signing.

Validate OAuth 2.1 Configuration

bash
python scripts/validate_oauth_config.py --config oauth.json

Validates OAuth 2.1 compliance (PKCE enabled, exact redirect URIs, etc.).

Examples

Auth.js + Next.js

Complete implementation with OAuth providers, credentials, and session management.

Location: examples/authjs-nextjs/

Keycloak + FastAPI

Self-hosted Keycloak with FastAPI integration via OIDC.

Location: examples/keycloak-fastapi/

Passkeys Demo

Runnable passkeys implementation with @simplewebauthn.

Location: examples/passkeys-demo/

Reference Documentation

  • references/oauth21-guide.md - OAuth 2.1 implementation guide
  • references/jwt-best-practices.md - JWT generation, validation, storage
  • references/passkeys-webauthn.md - Passkeys/WebAuthn implementation
  • references/authorization-patterns.md - RBAC, ABAC, ReBAC comparison
  • references/password-hashing.md - Argon2id parameters, migration

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Securing Authentication AI skill do?

Authentication, authorization, and API security implementation. Use when building user systems, protecting APIs, or implementing access control. Covers OAuth 2.1/OIDC, JWT patterns, sessions, Passkeys/WebAuthn, RBAC/ABAC/ReBAC, policy engines (OPA, Casbin, SpiceDB), managed auth (Clerk, Auth0), self-hosted (Keycloak, Ory), and API security best practices.

Why use Securing Authentication on TypingMind?

Because you install it once and use it with any model. Securing Authentication is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Securing Authentication in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ancoleman/ai-design-components/tree/main/skills/securing-authentication. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Securing Authentication?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Securing Authentication?

As many as you like. As long as a model supports skills, you can use Securing Authentication with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Securing Authentication AI skill free?

Yes. It is published on GitHub by ancoleman under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇