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:
"configuring oauth2 authorization flow"
"Configure secure OAuth 2"
When deploying or configuring configuring oauth2 authorization flow capabilities in your environment
When establishing security controls aligned to compliance requirements
When building or improving security architecture for this domain
When conducting security assessments that require this implementation
Prerequisites
- Familiarity with identity access management concepts and tools
- Access to a test or lab environment for safe execution
- Python 3.8+ with required dependencies installed
- Appropriate authorization for any testing activities
Objectives
- Implement Authorization Code flow with PKCE for public and confidential clients
- Configure Client Credentials flow for machine-to-machine communication
- Design least-privilege scope hierarchies
- Implement secure token storage, refresh, and revocation
- Apply OAuth 2.1 best practices and RFC 9700 security recommendations
- Validate token integrity and prevent common OAuth attacks
Key Concepts
This section covers key concepts for configuring oauth2 authorization flow.
- Ensure all prerequisites are met before proceeding
- Follow the documented workflow steps in sequence
- Record results and any anomalies encountered during this phase
OAuth 2.0 Grant Types
- Authorization Code + PKCE: Recommended for all client types (web, mobile, SPA). PKCE is mandatory in OAuth 2.1.
- Client Credentials: Machine-to-machine authentication without user context.
- Device Authorization Grant (RFC 8628): For input-constrained devices (smart TVs, CLI tools).
- 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:
- Client generates random
code_verifier (43-128 characters, unreserved URI chars)
- Client computes
code_challenge = BASE64URL(SHA256(code_verifier))
- Authorization request includes
code_challenge and code_challenge_method=S256
- Token request includes original
code_verifier
- Server validates
SHA256(code_verifier) matches stored code_challenge
Token Types
- Access Token: Short-lived (5-60 min), bearer or DPoP-bound
- Refresh Token: Long-lived, single-use with rotation
- ID Token (OIDC): JWT containing user identity claims
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()}
- Scope the task — define objectives, boundaries, and success criteria
- Gather information — collect all necessary data and context before proceeding
- Execute the core workflow — follow the domain-specific steps methodically
- Validate results — verify outputs against expected outcomes or baselines
- Document findings — record results, anomalies, and recommendations
Step 1: Authorization Code Flow with PKCE
- Generate cryptographically random code_verifier (min 43 chars)
- Compute code_challenge using S256 method
- Redirect user to authorization endpoint with parameters:
- response_type=code
- client_id, redirect_uri, scope, state
- code_challenge, code_challenge_method=S256
- User authenticates and consents
- Authorization server redirects with authorization code
- Exchange code + code_verifier for tokens at token endpoint
- Validate state parameter matches original value
Step 2: Scope Design
- Define granular scopes:
read:users, write:orders, admin:settings
- Follow least-privilege: request minimum scopes needed
- Implement scope validation on resource server
- Document scope hierarchy and consent requirements
Step 3: Token Security
- Store tokens securely (httpOnly cookies for web, keychain for mobile)
- Implement token refresh with rotation (one-time-use refresh tokens)
- Set appropriate expiration: access tokens 5-15 min, refresh tokens 8-24 hrs
- Enable DPoP (Demonstration of Proof-of-Possession) for sender-constrained tokens
- Implement token revocation endpoint
Step 4: Client Credentials Flow
- Register service client with client_id and client_secret
- Request token: POST /oauth/token with grant_type=client_credentials
- Include scope for required permissions
- Store client_secret securely (vault, env vars, not code)
- Implement certificate-based client authentication for higher assurance
Step 5: Security Hardening
- Enforce PKCE for all authorization code flows
- Use exact redirect URI matching (no wildcards)
- Implement CSRF protection with state parameter
- Enable refresh token rotation and revocation on reuse detection
- Apply RFC 9700 security best practices
- Block implicit grant and ROPC (removed in OAuth 2.1)
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
- Using implicit grant (removed in OAuth 2.1) instead of authorization code + PKCE
- Storing tokens in localStorage (XSS vulnerable) instead of httpOnly cookies
- Not validating state parameter enabling CSRF attacks
- Using wildcard redirect URIs allowing open redirect exploitation
- Not implementing refresh token rotation allowing token theft persistence
Verification
When NOT to Use
- You need to implement from scratch (use implementing-* skills)
- Task is about testing the configuration (use performing-* skills)
- You need to analyze misconfigurations (use analyzing-* skills)
- Task is about building automation (use building-* skills)
- You don't have admin access to the system
- Task requires vendor professional services
Red Flags
- Performing actions without explicit written authorization from the asset owner
- Testing against production systems without a defined scope and rules of engagement
- Sharing sensitive findings or credentials in unencrypted communications
- Failing to properly scope and contain the assessment before starting
Process
- Analyze the task requirements
- Apply domain expertise
- Verify output quality
1---2name: configuring-oauth2-authorization-flow3description: Use when configuring secure OAuth 2.0 authorization flows including Authorization4 Code with PKCE, Client Credentials, and Device Authorization Grant. This skill covers5 flow selection, PKCE implementation, token6domain: cybersecurity7subdomain: identity-access-management8tags:9- iam10- identity11- access-control12- authentication13- authorization14- oauth215- oidc16- pkce17version: '1.0'18author: oyi7719license: Apache-2.020nist_csf:21- PR.AA-0122- PR.AA-0223- PR.AA-0524- PR.AA-0625category: cybersecurity26metadata:27 source: https://skillmd.com/skills/oyi77/configuring-oauth2-authorization-flow28---2930# Configuring OAuth 2.0 Authorization Flow3132## Overview33Configure 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.34353637## Anti-Rationalization Table3839| Rationalization | Reality |40|---|---|41| "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. |42| "I already know this topic" | Familiarity breeds shortcuts. Use the checklist to verify you haven't missed critical steps. |43| "This doesn't apply to my situation" | The patterns here generalize across contexts. Adapt, don't skip — the underlying principles hold. |44| "One more tool will fix it" | Adding complexity rarely solves process gaps. Master the core workflow first. |4546## When to Use47**Trigger phrases:**48- "configuring oauth2 authorization flow"49- "Configure secure OAuth 2"505152- When deploying or configuring configuring oauth2 authorization flow capabilities in your environment53- When establishing security controls aligned to compliance requirements54- When building or improving security architecture for this domain55- When conducting security assessments that require this implementation5657## Prerequisites5859- Familiarity with identity access management concepts and tools60- Access to a test or lab environment for safe execution61- Python 3.8+ with required dependencies installed62- Appropriate authorization for any testing activities6364## Objectives65- Implement Authorization Code flow with PKCE for public and confidential clients66- Configure Client Credentials flow for machine-to-machine communication67- Design least-privilege scope hierarchies68- Implement secure token storage, refresh, and revocation69- Apply OAuth 2.1 best practices and RFC 9700 security recommendations70- Validate token integrity and prevent common OAuth attacks7172## Key Concepts7374This section covers key concepts for configuring oauth2 authorization flow.7576- Ensure all prerequisites are met before proceeding77- Follow the documented workflow steps in sequence78- Record results and any anomalies encountered during this phase79### OAuth 2.0 Grant Types801. **Authorization Code + PKCE**: Recommended for all client types (web, mobile, SPA). PKCE is mandatory in OAuth 2.1.812. **Client Credentials**: Machine-to-machine authentication without user context.823. **Device Authorization Grant (RFC 8628)**: For input-constrained devices (smart TVs, CLI tools).834. **Refresh Token**: Long-lived token to obtain new access tokens without re-authentication.8485### PKCE (Proof Key for Code Exchange)86PKCE (RFC 7636) prevents authorization code interception attacks:871. Client generates random `code_verifier` (43-128 characters, unreserved URI chars)882. Client computes `code_challenge = BASE64URL(SHA256(code_verifier))`893. Authorization request includes `code_challenge` and `code_challenge_method=S256`904. Token request includes original `code_verifier`915. Server validates `SHA256(code_verifier)` matches stored `code_challenge`9293### Token Types94- **Access Token**: Short-lived (5-60 min), bearer or DPoP-bound95- **Refresh Token**: Long-lived, single-use with rotation96- **ID Token (OIDC)**: JWT containing user identity claims9798## Workflow99100```python101# Example: IOC detection102import re103104IOC_PATTERNS = {105 "ip": r"\b(?:\d{1,3}\.){3}\d{1,3}\b",106 "domain": r"\b[a-z0-9-]+\.[a-z]{2,}\b",107 "hash_md5": r"\b[a-f0-9]{32}\b",108 "hash_sha256": r"\b[a-f0-9]{64}\b",109}110111def extract_iocs(text: str) -> dict:112 return {k: re.findall(v, text) for k, v in IOC_PATTERNS.items()}113```1141151. **Scope the task** — define objectives, boundaries, and success criteria1162. **Gather information** — collect all necessary data and context before proceeding1173. **Execute the core workflow** — follow the domain-specific steps methodically1184. **Validate results** — verify outputs against expected outcomes or baselines1195. **Document findings** — record results, anomalies, and recommendations120### Step 1: Authorization Code Flow with PKCE1211. Generate cryptographically random code_verifier (min 43 chars)1222. Compute code_challenge using S256 method1233. Redirect user to authorization endpoint with parameters:124 - response_type=code125 - client_id, redirect_uri, scope, state126 - code_challenge, code_challenge_method=S2561274. User authenticates and consents1285. Authorization server redirects with authorization code1296. Exchange code + code_verifier for tokens at token endpoint1307. Validate state parameter matches original value131132### Step 2: Scope Design133- Define granular scopes: `read:users`, `write:orders`, `admin:settings`134- Follow least-privilege: request minimum scopes needed135- Implement scope validation on resource server136- Document scope hierarchy and consent requirements137138### Step 3: Token Security139- Store tokens securely (httpOnly cookies for web, keychain for mobile)140- Implement token refresh with rotation (one-time-use refresh tokens)141- Set appropriate expiration: access tokens 5-15 min, refresh tokens 8-24 hrs142- Enable DPoP (Demonstration of Proof-of-Possession) for sender-constrained tokens143- Implement token revocation endpoint144145### Step 4: Client Credentials Flow1461. Register service client with client_id and client_secret1472. Request token: POST /oauth/token with grant_type=client_credentials1483. Include scope for required permissions1494. Store client_secret securely (vault, env vars, not code)1505. Implement certificate-based client authentication for higher assurance151152### Step 5: Security Hardening153- Enforce PKCE for all authorization code flows154- Use exact redirect URI matching (no wildcards)155- Implement CSRF protection with state parameter156- Enable refresh token rotation and revocation on reuse detection157- Apply RFC 9700 security best practices158- Block implicit grant and ROPC (removed in OAuth 2.1)159160## Security Controls161| Control | NIST 800-53 | Description |162|---------|-------------|-------------|163| Access Control | AC-3 | Token-based access enforcement |164| Authentication | IA-5 | Client credential management |165| Session Management | SC-23 | Token lifecycle management |166| Audit | AU-3 | Log all token issuance and revocation |167| Cryptographic Protection | SC-13 | PKCE and token signing |168169## Common Pitfalls170- Using implicit grant (removed in OAuth 2.1) instead of authorization code + PKCE171- Storing tokens in localStorage (XSS vulnerable) instead of httpOnly cookies172- Not validating state parameter enabling CSRF attacks173- Using wildcard redirect URIs allowing open redirect exploitation174- Not implementing refresh token rotation allowing token theft persistence175176## Verification177- [ ] Authorization Code + PKCE flow completes successfully178- [ ] PKCE code_challenge validated at token endpoint179- [ ] State parameter prevents CSRF180- [ ] Access tokens expire within configured lifetime181- [ ] Refresh token rotation issues new refresh token each use182- [ ] Token revocation invalidates both access and refresh tokens183- [ ] Client Credentials flow works for service-to-service calls184- [ ] Scopes correctly enforced at resource server185## When NOT to Use186187- You need to implement from scratch (use implementing-* skills)188- Task is about testing the configuration (use performing-* skills)189- You need to analyze misconfigurations (use analyzing-* skills)190- Task is about building automation (use building-* skills)191- You don't have admin access to the system192- Task requires vendor professional services193194195## Red Flags196197- Performing actions without explicit written authorization from the asset owner198- Testing against production systems without a defined scope and rules of engagement199- Sharing sensitive findings or credentials in unencrypted communications200- Failing to properly scope and contain the assessment before starting201202## Process2032041. Analyze the task requirements2052. Apply domain expertise2063. Verify output quality