调试 OAuth 2.0 与 OIDC 流程;追踪授权码、PKCE、客户端凭证和隐式流程;诊断重定向 URI 不匹配、作用域问题及令牌错误。
OAuth 调试器是一项面向实际任务的技能,主要用于调试 OAuth 2.0 和 OpenID 连接流, 不猜测. 追踪授权流的每个步骤, 确定它断裂之处( 直接URI 错配、 范围问题、 符号外昌)。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
无需猜测即可调试 OAuth 2.0 和 OpenID Connect 流程。逐步追踪授权流程,精准定位失败环节(如重定向 URI 不匹配、scope 配置问题、token 交换失败、JWKS 配置错误等),并提供确切修复方案。
适用场景:遇到“oauth 不工作”、“重定向 URI 不匹配”、“invalid_grant”、“登录流程中断”、“OIDC 配置问题”、“token 交换失败”、“PKCE 错误”、“授权码错误”,或单点登录(SSO)/社交登录异常时。
trace — 逐步追踪 OAuth 流程# OpenID Connect 发现
curl -s "https://$AUTH_DOMAIN/.well-known/openid-configuration" | python3 -c "
import json, sys
config = json.load(sys.stdin)
print('Authorization endpoint:', config.get('authorization_endpoint', '❌ MISSING'))
print('Token endpoint:', config.get('token_endpoint', '❌ MISSING'))
print('JWKS URI:', config.get('jwks_uri', '❌ MISSING'))
print('Supported flows:', config.get('grant_types_supported', ['not listed']))
print('Supported scopes:', config.get('scopes_supported', ['not listed']))
print('Token signing:', config.get('id_token_signing_alg_values_supported', ['not listed']))
"
# 检查 JWKS 端点
curl -s "https://$AUTH_DOMAIN/.well-known/jwks.json" | python3 -c "
import json, sys
jwks = json.load(sys.stdin)
for key in jwks.get('keys', []):
print(f'Key ID: {key.get("kid")} | Algorithm: {key.get("alg")} | Use: {key.get("use")}')
"
针对 Authorization Code + PKCE 流程:
# 检查授权 URL 构造 # 必需参数: # - response_type=code # - client_id=# - redirect_uri=<必须完全匹配> # - scope=<请求的 scopes> # - state= # - code_challenge= # - code_challenge_method=S256 python3 -c " import hashlib, base64, secrets verifier = secrets.token_urlsafe(32) challenge = base64.urlsafe_b64encode(hashlib.sha256(verifier.encode()).digest()).rstrip(b'=').decode() print(f'code_verifier: {verifier}') print(f'code_challenge: {challenge}') print(f'code_challenge_method: S256') "
# 测试 token 交换
curl -s -X POST "https://$AUTH_DOMAIN/oauth/token"
-H "Content-Type: application/x-www-form-urlencoded"
-d "grant_type=authorization_code"
-d "code=$AUTH_CODE"
-d "redirect_uri=$REDIRECT_URI"
-d "client_id=$CLIENT_ID"
-d "client_secret=$CLIENT_SECRET"
-d "code_verifier=$CODE_VERIFIER" | python3 -c "
import json, sys
resp = json.load(sys.stdin)
if 'access_token' in resp:
print('✅ Token exchange successful')
print(f'Access token type: {resp.get("token_type")}')
print(f'Expires in: {resp.get("expires_in")}s')
print(f'Scopes: {resp.get("scope")}')
if 'id_token' in resp:
print(f'ID token: present')
if 'refresh_token' in resp:
print(f'Refresh token: present')
else:
print(f'❌ Error: {resp.get("error")}')
print(f'Description: {resp.get("error_description")}')
"
diagnose — 常见 OAuth 错误invalid_grant:
redirect_uri_mismatch:
http://localhost:3000 ≠ http://localhost:3000/http ≠ httpslocalhost:3000 ≠ localhost:3001/callback ≠ /auth/callbackinvalid_client:
invalid_scope:
email → openid email)access_denied:
# OAuth 调试报告 ## 流程:Authorization Code + PKCE ## 提供商:Auth0(tenant.auth0.com) ## 追踪结果 1. ✅ Discovery:已找到 .well-known/openid-configuration 2. ✅ 授权请求:参数合法 3. ✅ 用户已认证并完成授权 4. ❌ Token 交换:`invalid_grant` ## 诊断结论 - Token 请求中的 redirect_uri:`http://localhost:3000/callback` - 授权请求中的 redirect_uri:`http://localhost:3000/callback/` - 🔴 **末尾斜杠不匹配** — 两次请求中的 redirect_uri 必须完全一致 ## 修复方案 将 Token 请求中的 redirect_uri 改为 `http://localhost:3000/callback/`(带末尾斜杠) 或修改授权请求,移除末尾斜杠。 同时,请同步更新提供商后台注册的 redirect URIs 配置。
test-flow — 模拟 OAuth 流程客户端凭据(machine-to-machine):
curl -s -X POST "https://$AUTH_DOMAIN/oauth/token" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials" -d "client_id=$CLIENT_ID" -d "client_secret=$CLIENT_SECRET" -d "audience=$API_AUDIENCE"
刷新 Token:
curl -s -X POST "https://$AUTH_DOMAIN/oauth/token" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=refresh_token" -d "refresh_token=$REFRESH_TOKEN" -d "client_id=$CLIENT_ID"
security-check — 审计 OAuth 实现安全性识别潜在安全风险:
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.6万人学习
最新文章