← 返回
未分类 中文

Oauth Oidc

Deep OAuth 2.0 / OpenID Connect workflow—choosing flows for client type, PKCE, tokens and validation, scopes and consent, rotation, and common misconfigurati...
深入剖析 OAuth 2.0 / OpenID Connect 工作流——涵盖客户端流程选择、PKCE、令牌与验证、作用域与授权、轮换机制及常见配置错误。
codenova58 codenova58 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 419
下载
💾 0
安装
1
版本
#latest

概述

OAuth 2.0 / OIDC (Deep Workflow)

OAuth solves delegated authorization; OIDC adds identity on top. Most production bugs are wrong flow for client, token validation gaps, and confused redirect URIs.

When to Offer This Workflow

Trigger conditions:

  • Web, mobile, or SPA login; machine-to-machine clients
  • Debugging invalid_grant, redirect_uri mismatches, token replay
  • Hardening scopes, refresh rotation, logout

Initial offer:

Use six stages: (1) actors & client type, (2) select flow & PKCE, (3) tokens & validation, (4) scopes & consent UX, (5) session & logout, (6) operational hardening). Confirm IdP (Auth0, Cognito, Keycloak, Google, etc.).


Stage 1: Actors & Client Type

Goal: Classify confidential vs public clients and who holds secrets.

Rules

  • Server-side web app with secret: confidential; SPA and native: public → PKCE mandatory
  • M2M: client credentials or JWT assertion—no user in loop

Exit condition: Architecture diagram: browser, backend, IdP, resource server.


Stage 2: Select Flow & PKCE

Goal: Authorization Code (+ PKCE for public clients); avoid Implicit and ROPC for new apps.

Practices

  • Exact redirect URI allowlist—no wildcards that enable open redirects
  • State and nonce for CSRF and token binding (OIDC)
  • Mobile: custom URL schemes vs universal links—document trade-offs

Exit condition: Sequence diagram for login happy path and error paths.


Stage 3: Tokens & Validation

Goal: Access token for APIs; ID token for identity claims—validate issuer, audience, exp, signature (JWKS rotation).

Practices

  • Never use ID token as API bearer unless your architecture explicitly defines that (usually wrong)
  • Refresh token: rotation, reuse detection, secure storage (httpOnly cookie or secure OS storage on mobile)
  • Clock skew tolerance when validating exp

Exit condition: Documented validation steps in code or API gateway config.


Stage 4: Scopes & Consent

Goal: Least privilege scopes; incremental auth when possible.

UX

  • Clear consent copy; minimize scope creep at first login

Stage 5: Session & Logout

Goal: RP-initiated logout vs local session clearing—know what breaks SSO across apps.

Practices

  • Front-channel / back-channel logout when enterprise IdP requires

Stage 6: Operational Hardening

Goal: Rotate client secrets safely; monitor failed auth rates; alert on abnormal token issuance.

Pitfalls

  • Mixing dev and prod clients; leaking JWKS or introspection endpoints in client bundles

Final Review Checklist

  • [ ] Correct flow and PKCE for client class
  • [ ] Redirect URIs strict; state/nonce used appropriately
  • [ ] Token validation complete (sig, iss, aud, exp)
  • [ ] Refresh handling and rotation policy
  • [ ] Scopes minimal; logout behavior understood

Tips for Effective Guidance

  • Draw Authorization Code + PKCE as default for SPAs.
  • Call out BFF pattern when SPA cannot hold secrets and APIs need cookies.
  • Enterprise SAML bridge to OIDC adds quirks—defer to IdP docs when needed.

Handling Deviations

  • First-party only same-site: consider session cookie auth instead of full OAuth complexity if appropriate.
  • Legacy Implicit: migration plan to Code+PKCE with downtime window.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 08:31 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

it-ops-security

MoltGuard - Security & Antivirus & Guardrails

thomas-security
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装后可防止您和您的用户受到提示注入、数据泄露及恶意行为的侵害。
★ 116 📥 30,962
professional

Eastmoney

codenova58
访问并总结来自东方财富的公开市场数据、新闻和行业趋势,不包括交易或批量数据提取。
★ 1 📥 6,032
it-ops-security

OpenClaw Backup

alex3alex
备份与恢复 OpenClaw 数据。适用于创建备份、设置自动备份计划、从备份恢复或管理备份轮转。处理 ~/.openclaw 目录归档并包含适当的排除规则。
★ 90 📥 30,999