【问题标题】:Configure client_id as mandatory param for password grant type将 client_id 配置为密码授予类型的强制参数
【发布时间】:2020-11-24 10:24:55
【问题描述】:

使client_id 成为password 授权类型的强制参数的正确方法是什么? 使用此请求,我想将 client_id 设为强制值,并让 OAuth2 框架将其与返回到方法 loadClientByClientId 的结果进行比较

curl --location --request POST 'http://localhost:8080/engine/oauth/token' \
--header 'Authorization: Basic YWRtaW46cXdlcnR5' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=qwerty' \
--data-urlencode 'client_id=some_value' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'scope=read_profile'

实现这一点的最佳方法是什么?

【问题讨论】:

  • 为什么你认为client_id 不是强制性的?
  • 是的,我同意,我不知道其中 clientId 不是强制性的 Oauth2 的单个实现。像这样很好,因为这没有任何意义

标签: spring-security spring-security-oauth2


【解决方案1】:

您可以尝试使用来自docs 的方法validateScope(TokenRequest tokenRequest, ...) 实现自定义OAuth2RequestValidator

确保客户端请求了一组有效的范围。

可以访问TokenRequest.getRequestParameters()

编辑 另请参阅TokenEndpoint 的文档

客户端必须经过身份验证 (...) 才能访问此端点,并且客户端 ID 是从身份验证令牌中提取的。 (...)

【讨论】:

    猜你喜欢
    • 2015-07-18
    • 2016-06-20
    • 2014-09-08
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 2017-01-04
    • 2020-08-24
    • 2017-02-26
    相关资源
    最近更新 更多