OIDC / OAuth2 Mock
OAuth 2.0(RFC 6749)一侧有三个可对接的服务角色:Authorization Server(OIDC 里叫 OpenID Provider / OP)、Client(OIDC 里叫 Relying Party / RP)、Resource Server。术语对照与整体说明见 Mock 概览。
Authorization Server(OIDC:OpenID Provider / OP)
| 端点 | 路径 |
|---|---|
| Discovery | /.well-known/openid-configuration |
| Authorization | /oidc/authorize |
| Token | /oidc/token |
| UserInfo | /oidc/userinfo |
| JWKS | /oidc/jwks.json |
- 零注册:任意
client_id/redirect_uri均被接受,不校验 client secret。 - Authorization Code Flow + PKCE(S256 / plain);
refresh_token(scope 含offline_access时)与client_credentialsgrant。 - 两个固定测试用户 alice / bob;授权请求追加
&user=alice可跳过用户选择页(CI 免交互)。 - CORS 全开,可直接从浏览器前端调用。
Client(OIDC:Relying Party / RP)
控制台:https://mock.authn.tech/rp/
用本 Mock 作为客户端,连接任意外部 OP(Keycloak、Auth0、Okta、Azure AD,或本站 Mock OP),完整走一遍 Authorization Code + PKCE 登录:填入外部 OP 的 issuer 与 client_id → 自动拉取 Discovery → 发起登录 → 回调换令牌 → 用 OP 的 JWKS 验证 ID Token 签名 → 校验 iss/aud/nonce/exp → 调 UserInfo,逐步展示。
回调地址
https://mock.authn.tech/rp/callback需加入外部 OP 的白名单。
Resource Server(资源服务器 / 受保护 API)
说明页:https://mock.authn.tech/rs/ · 受保护端点 GET /rs/api
校验 access token 的签名、过期、token_use 与 scope(需含 profile)后返回受保护资源;权限不足返回 403 insufficient_scope,无 / 失效令牌返回 401 invalid_token。
调用顺序(授权码 + PKCE)
以「你的 RP + Mock OP」为例:
- RP 生成
code_verifier,算出code_challenge(S256),连同state、nonce把浏览器重定向到 OP 的/oidc/authorize。 - OP 展示测试用户选择页(或凭
&user=alice直接选定),带code+state回跳到 RP 的redirect_uri。 - RP 比对
state,用code+code_verifierPOST 到 OP 的/oidc/token。 - OP 校验 PKCE 后返回
id_token/access_token(及可选refresh_token)。 - RP 从 OP 的
/oidc/jwks.json取公钥验签id_token,并校验iss/aud/nonce/exp。 - RP 携
access_token调 OP 的/oidc/userinfo(或调 RS 的/rs/api)获取用户信息 / 受保护资源。
想直接看效果?本站有一个真实可点的 OIDC 登录演示,一键跑完上述流程并展示每步解析结果。
授权端点示例(替换成你的回调地址):
https://mock.authn.tech/oidc/authorize?client_id=demo&redirect_uri=https://your-app.example/callback&response_type=code&scope=openid+profile+email&state=xyz&nonce=n-abc
换取令牌:
curl -X POST https://mock.authn.tech/oidc/token \
-d grant_type=authorization_code \
-d code=<code> \
-d redirect_uri=https://your-app.example/callback \
-d client_id=demo
拿到的 id_token 可直接丢进 JWT 解析器 查看。