@FeignClient(name = "Authorization-API", url = "https://www.reddit.com/api/v1")
public interface AuthorizationApi {
@RequestMapping(method = RequestMethod.POST, value = "/access_token")
Token getToken(@PathVariable("grant_type") String grantType,
@PathVariable String code,
@PathVariable("redirect_uri") String redirectUrl,
@RequestHeader(name = "Authorization") String authorizationHeader,
@RequestHeader("User-agent") String agent
);
}
电话:
Token token = authorizationApi.getToken(
"authorization_code",
code,
REDIRECT_URI,
getAuthorizationCredentials(),
"porymol");
System.out.println(token.access_token()); //returns null
令牌记录:
public record Token(String access_token, String token_type, Long expires_in, String scope, String refresh_token) {
}
当我向 Postman 提出请求时,我得到了这样的回应:
{
"access_token": "token",
"token_type": "bearer",
"expires_in": 86400,
"refresh_token": "token",
"scope": "read"
}
尝试从令牌获取任何值时返回null
Java 17, Spring Boot 3
你知道出了什么问题吗?
1条答案
按热度按时间djmepvbi1#
首先,你声明了两个路径变量,它们没有显示路径:
@PathVariable String code
和@PathVariable("redirect_uri") String redirectUrl
。总的来说,看起来您正在尝试请求一个需要内容类型为
application/x-www-form-urlencoded
的请求的oauth访问令牌。也许这有帮助:How to POST form-url-encoded data with Spring Cloud Feign