【问题标题】:Spring OAuth2.0: How can I add a custom query parameter to the Authorization code (/oauth/authorize) response?Spring OAuth2.0:如何向授权码(/oauth/authorize)响应添加自定义查询参数?
【发布时间】:2018-07-13 12:40:07
【问题描述】:

我看到授权码是在AuthorizationEndpoint.java里面的redirectUri里面插入的

private String getSuccessfulRedirect(AuthorizationRequest authorizationRequest, String authorizationCode) {

    if (authorizationCode == null) {
        throw new IllegalStateException("No authorization code found in the current request scope.");
    }

    Map<String, String> query = new LinkedHashMap<String, String>();
    query.put("code", authorizationCode);

    String state = authorizationRequest.getState();
    if (state != null) {
        query.put("state", state);
    }

    return append(authorizationRequest.getRedirectUri(), query, false);
}

我希望能够在 query.put() 所在的位置添加一个 sn-p 代码,但我无法成功扩展该类。我不知道在哪里/如何将其配置为我想首先访问的身份验证端点。我还发现我需要扩展整个类有点极端,这样我就可以添加几行代码,以便将另一个查询参数附加到授权代码响应 uri。

谢谢

【问题讨论】:

  • Spring Security OAuth2 只实现了OAuth2 spec,所以你必须使用规范支持的方式。您可以使用state 查询参数或redirect_uri 查询参数。

标签: spring-security spring-oauth2


【解决方案1】:

我不知道为什么我的问题被否决了,但无论如何...

因为@dur 的评论基本上说我不能那样做。谢谢顺便说一句(我看不出有什么方法可以支持你的评论,我是新来的)。

解决方案:我决定创建一个自定义身份验证过滤器,在登录页面出现之前进行过滤。我做了一些验证并将其传递给身份验证。从那里,我为我的过滤器添加了一个自定义成功处理程序并重定向到/oauth/authorize,以便跳转到我想要的授权代码流。

【讨论】:

    猜你喜欢
    • 2017-08-31
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 2021-03-25
    • 2019-09-23
    • 1970-01-01
    相关资源
    最近更新 更多