Home

Test [[${clientDetailsDto.clientId}]]

针对不同的grant_type提供不同的测试URL, 完整的OAuth测试请访问spring-oauth-client项目.

请先输入client_secret:

Test [authorization_code]

输入每一步必要的信息后点击其下面的按钮地址.

  1. 从 spring-oauth-server获取 'code'
    client_id
    redirect_uri

    若配置有多个redirect_uri可自行修改(默认使用第一个)

    scope
    state

    每次随机生成, spring-oauth-server原封不动返回(防止会话劫持攻击)

    response_type

    固定值

    GET
  2. 用 'code' 换取 'access_token'
    输入第一步获取的'code'并点击按钮链接地址.
    client_id
    client_secret
    redirect_uri

    若配置有多个redirect_uri可自行修改(默认使用第一个)

    grant_type

    固定值

    code

    请输入code值

    POST
Test [authorization_code + PKCE]

输入每一步必要的信息后点击其下面的链接地址.

  1. 从 spring-oauth-server获取 'code'
    PKCE流程在开始前需要先通过代码生成code_verifiercode_challenge (如何生成详见工具类 PKCEUtils.java );
    生成后在获取'code'时要在已有的参数基础上再增加两个参数:
    code_challenge 对 code_verifier 使用指定算法进行计算(digest)并base encode的值
    code_challenge_method 固定值:S256

    client_id
    redirect_uri

    若配置有多个redirect_uri可自行修改(默认使用第一个)

    scope
    state

    每次随机生成, spring-oauth-server原封不动返回(防止会话劫持攻击)

    response_type

    固定值

    code_challenge_method

    固定值

    code_challenge

    (后台代码生成,不可修改)

    GET
  2. 用 'code' 换取 'access_token'
    输入第一步获取的code并点击按钮地址.
    client_id
    client_secret
    redirect_uri

    若配置有多个redirect_uri可自行修改(默认使用第一个)

    grant_type

    固定值

    code

    请输入code值

    code_verifier

    (后台代码生成,不可修改)

    POST
Test [password] OAuth2.1不支持

输入username, password 后点击链接地址.

username:
password:
POST
Test [device_code] OAuth2.1新增
  1. 设备上请求 /oauth2/device_authorization获取 user_code, device_code,verification_uri

    client_id
    client_secret
    scope
    POST

    一般此步骤是在设备上通过代码来完成, 此处只作演示流程

  2. 在设备上展示user_code或显示一个二维码(内容为verification_uri_complete URL)

    用已经登录成功的浏览器(或另一个已经认证的设备)访问verification_uri_complete URL(可通过扫码等方式获取内容)

    此处方便演示, 请点击/oauth2/device_verification并输入上一步获取到的user_code (若未认证将跳转到登录)

    提示:此步骤必须在有效时间内完成, user_code的有效时长在上一步中返回的数据expires_in来决定(单位:秒, 默认5分钟)

  3. 在第2步进行的同时, 设备上后台将定时(如每隔5秒)向spring-oauth-server发起获取token的请求/oauth2/token (需要使用第1步中获取到 device_code 的值),
    直到获取成功(即第2步操作完成授权设备登录)或超时(即设备轮询请求等待的时长超出第1步返回的时间expires_in)

    请输入device_code后点击按钮地址.

    client_id
    client_secret
    grant_type

    固定值

    device_code

    请输入device_code

    POST

    提示:在第2步进行过程中调用第3步获取token API时会响应等待授权的结果(Http状态码 400, error='authorization_pending')

Test [jwt-bearer] OAuth2.1新增
  • jwt-bearer是一类增强client端请求安全性的断言(assertion)实现; 通过类似'双向SSL'的机制来让server端验证client端的签名实现强安全性.

  • 当注册或添加client端时需要填写一个jwk URL地址(用来获取验签的公钥), 指定认证jwt签名算法(如RS256), 设置methods为client_secret_jwt(对称算法, 使用client_secret为MacKey)或private_key_jwt(非对称算法)

    注意: grant_type不能只有jwt-bearer, 无实用意义

cURL示例:
curl --location 'http://localhost:8080/oauth2/token' \
  --header 'Content-Type: application/json' \
  --form 'client_id="dofOx6hjxlWw9qe2bnFvqbiPhuWwGWdn"' \
  --form 'client_assertion_type="urn:ietf:params:oauth:client-assertion-type:jwt-bearer"' \
  --form 'scope="openid"' \
  --form 'grant_type="client_credentials"' \
  --form 'client_assertion="eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJkb2ZPeDZoanhsV3c5..."' \
  --form 'client_secret="dofOx6hjxlWw9qe2bnFvqbiPhuWwGWdn"'
增加两个请求参数:
client_assertion_type 固定值: urn:ietf:params:oauth:client-assertion-type:jwt-bearer
client_assertion 使用提供的 jwk URL中的 private_key进行签名生成的 JWT(如何生成详见: JwtBearerFlowTest.java)

输入client_assertion值, 点击按钮地址即可测试

client_id
client_secret
scope
grant_type

grant_type根据需要值可以是authorization_code refresh_token

client_assertion_type

固定值

client_assertion

如何生成client_assertion, 详见示例类: JwtBearerFlowTest.java

POST
Test [client_credentials]

点击按钮地址即可测试

client_id
client_secret
scope
grant_type

固定值

POST
Test [refresh_token]

输入refresh_token 后点击链接地址.

client_id
client_secret
grant_type

固定值

refresh_token

请输入 refresh_token 值

POST
复用refresh_token: