【问题标题】:oAuth2.0 - Fitbit does not return auth code (attributes cannot be empty error)oAuth2.0 - Fitbit 不返回验证码(属性不能为空错误)
【发布时间】:2020-09-16 10:37:31
【问题描述】:

我一直在努力为 Fitbit API 实施授权代码授予流程。我已经设置了 WebSecurityConfigurerAdapter,并且我被正确地重定向到了 Fitbit /oauth2/authorize 页面,我可以在其中授予权限。但是,当我允许我的应用程序访问时,它会显示以下内容:authorization_request_not_found。此外,网址不包含代码。 我真的找不到关于如何使用 Spring Boot 实现下一步的好文档。 如果有人能指出我正确的方向,将不胜感激。谢谢 堆:

【问题讨论】:

    标签: spring-boot oauth-2.0 fitbit


    【解决方案1】:

    问题出在访问令牌请求中。按照授权代码授予流程,您需要将授权标头设置为基本。您的 client_id 和 secret 用冒号​​连接并编码为 Base64 将是您的基本授权标头值。

    您可以在官方文档中找到更多信息:Access Token Request

    在 Spring Security 中实现这一点非常简单。只需按照本教程进行操作: Custom Token Request

    CustomRequestEntityConverter 类的转换方法应如下所示:

    @Override
    public RequestEntity<?> convert(OAuth2AuthorizationCodeGrantRequest req) {
        RequestEntity<?> entity = defaultConverter.convert(req);
        MultiValueMap<String, String> headers = entity.getHeaders();
    
        String authorization = Base64.getEncoder().encodeToString(BASIC_AUTHORIZATION.getBytes());
    
        HttpHeaders httpHeaders = new HttpHeaders();
    
        httpHeaders.setBasicAuth(authorization);
        httpHeaders.addAll(headers);
    
        return new RequestEntity<>(entity.getBody(), httpHeaders, entity.getMethod(), entity.getUrl());
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多