【问题标题】:Getting Bad request while posting form-url-encoded data with Feign client使用 Feign 客户端发布表单 URL 编码数据时出现错误请求
【发布时间】:2021-07-21 05:58:41
【问题描述】:

响应:{"httpCode":"400","httpMessage":"Bad Request","moreInformation":"API 请求中缺少一个或多个必需的 API 参数。"}

从日志中我可以看到所有参数都按如下方式传递 grant_type=client_credentials&scope=abcd&client_id=sample&client_secret=sample

@FeignClient(name = "tru", url = "${api.tru.url}", configuration = TruConfig.class)
public interface TruClient {
    @PostMapping(value = "/tru/oauth2/token", consumes = APPLICATION_FORM_URLENCODED_VALUE)
    AuthTokenResponse getAccessToken(@RequestBody MultiValueMap<String, ?> formParams);

     class FeignSupportConfig {

        @Autowired
        private ObjectFactory<HttpMessageConverters> messageConverters;

         @Bean
         public Encoder feignFormEncoder() {
             return new FormEncoder(new SpringEncoder(messageConverters));
         }
    }
}

【问题讨论】:

    标签: spring spring-boot spring-cloud-feign feign


    【解决方案1】:

    我认为“范围”是不必要的。 在此处查看此文档https://auth0.com/docs/flows/call-your-api-using-the-client-credentials-flow 你的参数应该是这样的

    "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&audience=YOUR_API_IDENTIFIER"
    

    【讨论】:

    • 您是否在没有“范围”的情况下进行了测试??因为我在任何文档中都没有看到该字段您是否使用了自定义授权服务器?
    • 是的。这是第三方的自定义身份验证服务器
    猜你喜欢
    • 2019-06-21
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多