82 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# oauth_test - OAuth2/OIDC 独立联调客户端
这是一个**完全独立**的静态测试页,不依赖现有系统前端工程,用于联调你们平台的 OAuth2/OIDC 端点。
## 文件说明
- `index.html`:单页联调客户端(内联 JS/CSS
- `README.md`:使用说明
## 启动方式
任选其一:
1. 直接双击打开 `index.html`
2. 使用任意静态服务启动(推荐,避免部分浏览器本地文件策略影响)
示例PowerShell
```powershell
cd D:\Projects\PHP\BastionSSO\oauth_test
python -m http.server 8800
```
然后访问:`http://localhost:8800/index.html`
## 建议默认配置(按当前项目)
假设你的服务端是 `http://localhost`
- `issuer`: `http://localhost`
- `discovery_endpoint`: `http://localhost/.well-known/openid-configuration`
- `authorize_endpoint`: `http://localhost/oauth/authorize`
- `token_endpoint`: `http://localhost/oauth/token`
- `userinfo_endpoint`: `http://localhost/oauth/userinfo`
- `revoke_endpoint`: `http://localhost/oauth/revoke`
## 支持流程
- Discovery 自动发现并回填端点
- Authorization Code 授权跳转
- 解析回调 `code/error/state`
- 换取 Token默认 Basic 优先,可切换 post
- 拉取 UserInfo
- Refresh Token
- Revoke Tokenaccess/refresh
- PKCE 开关S256
## 使用步骤(推荐)
1. 填写 `issuer`,点击“按 issuer 自动填充端点”
2. 填写 `client_id``client_secret``redirect_uri``scope`
3. 点击“发起授权”,在 OAuth 页面登录并同意
4. 回跳后点击“解析回调”
5. 点击“换取 Token”
6. 点击“拉取 UserInfo”验证用户信息返回
7. 可继续测试“刷新 Token”和“撤销 Token”
## 常见问题
1. `invalid_client`
- 检查 `client_id/client_secret` 是否正确
- 检查客户端认证方式Basic / post是否与服务端一致
2. `invalid_grant`
- `code` 可能已过期或已使用
- `redirect_uri` 与授权时不一致
3. `redirect_uri mismatch`
- 确保客户端配置中的回调地址与请求参数完全一致(协议/域名/端口/路径)
4. 浏览器报 `Failed to fetch`
- 多数是 CORS 或网络策略问题
- 需要服务端放行当前 Origin以及 `Authorization` / `Content-Type` 请求头
5. `scope` 相关错误
- 请求 scope 必须是客户端允许 scope 的子集
## 备注
- 页面配置和 token 状态会保存在浏览器 `localStorage`
- 本目录不会接入现有系统菜单、路由或打包流程。