使用外部客户端发布表单url编码数据时收到错误请求

ia2d9nvy  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(295)

响应:{“httpcode”:“400”,“httpmessage”:“错误请求”,“moreinformation”:“api请求中缺少一个或多个必需的api参数。”}
从日志中,我可以看到所有参数的传递方式如下:grant\u type=client\u credentials&scope=ban&client\u id=sample&client\u 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));
         }
    }
}
kfgdxczn

kfgdxczn1#

我认为“范围”是不必要的。请参阅此处的文档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"

相关问题