Configuring oauth2 authorization flow

From oyi77/1ai-skills · View interactive version

Configuring oauth2 authorization flow is an AI agent skill from the GitHub repository oyi77/1ai-skills. Use when configuring secure OAuth 2.0 authorization flows including Authorization Code with PKCE, Client Credentials, and Device Authorization Grant. This skill covers flow selection, PKCE implementation, token

How to use this skill

Skill file

Configuring OAuth 2.0 Authorization Flow

Overview

Configure secure OAuth 2.0 authorization flows including Authorization Code with PKCE, Client Credentials, and Device Authorization Grant. This skill covers flow selection, PKCE implementation, token lifecycle management, scope design, and alignment with OAuth 2.1 security requirements.

Anti-Rationalization Table

| Rationalization | Reality |

|---|---|

| "I'll figure it out as I go" | A structured approach saves time and reduces errors. Follow the workflow in this skill rather than improvising. |

| "I already know this topic" | Familiarity breeds shortcuts. Use the checklist to verify you haven't missed critical steps. |

| "This doesn't apply to my situation" | The patterns here generalize across contexts. Adapt, don't skip — the underlying principles hold. |

| "One more tool will fix it" | Adding complexity rarely solves process gaps. Master the core workflow first. |

When to Use

Trigger phrases:

Prerequisites

Objectives

Key Concepts

This section covers key concepts for configuring oauth2 authorization flow.

OAuth 2.0 Grant Types

  1. Authorization Code + PKCE: Recommended for all client types (web, mobile, SPA). PKCE is mandatory in OAuth 2.1.
  2. Client Credentials: Machine-to-machine authentication without user context.
  3. Device Authorization Grant (RFC 8628): For input-constrained devices (smart TVs, CLI tools).
  4. Refresh Token: Long-lived token to obtain new access tokens without re-authentication.

PKCE (Proof Key for Code Exchange)

PKCE (RFC 7636) prevents authorization code interception attacks:

  1. Client generates random code_verifier (43-128 characters, unreserved URI chars)
  2. Client computes code_challenge = BASE64URL(SHA256(code_verifier))
  3. Authorization request includes code_challenge and code_challenge_method=S256
  4. Token request includes original code_verifier
  5. Server validates SHA256(code_verifier) matches stored code_challenge

Token Types

Workflow

# Example: IOC detection
import re

IOC_PATTERNS = {
    "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",
    "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",
    "hash_md5": r"\b[a-f0-9]{32}\b",
    "hash_sha256": r"\b[a-f0-9]{64}\b",
}

def extract_iocs(text: str) -> dict:
    return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}
  1. Scope the task — define objectives, boundaries, and success criteria
  2. Gather information — collect all necessary data and context before proceeding
  3. Execute the core workflow — follow the domain-specific steps methodically
  4. Validate results — verify outputs against expected outcomes or baselines
  5. Document findings — record results, anomalies, and recommendations

Step 1: Authorization Code Flow with PKCE

  1. Generate cryptographically random code_verifier (min 43 chars)
  2. Compute code_challenge using S256 method
  3. Redirect user to authorization endpoint with parameters:
  1. User authenticates and consents
  2. Authorization server redirects with authorization code
  3. Exchange code + code_verifier for tokens at token endpoint
  4. Validate state parameter matches original value

Step 2: Scope Design

Step 3: Token Security

Step 4: Client Credentials Flow

  1. Register service client with client_id and client_secret
  2. Request token: POST /oauth/token with grant_type=client_credentials
  3. Include scope for required permissions
  4. Store client_secret securely (vault, env vars, not code)
  5. Implement certificate-based client authentication for higher assurance

Step 5: Security Hardening

Security Controls

| Control | NIST 800-53 | Description |

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

| Access Control | AC-3 | Token-based access enforcement |

| Authentication | IA-5 | Client credential management |

| Session Management | SC-23 | Token lifecycle management |

| Audit | AU-3 | Log all token issuance and revocation |

| Cryptographic Protection | SC-13 | PKCE and token signing |

Common Pitfalls

Verification

When NOT to Use

Red Flags

Process

  1. Analyze the task requirements
  2. Apply domain expertise
  3. Verify output quality
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.