我的问题是关于 Linkedin api 的 OAuth2 访问 token 响应。当我尝试获取此 token 时,我收到以下响应:
{"access_token":"...","expires_in":...}
但事实是,根据OAuth2 documentation (在 5.1 段中)应该至少还有一个必需参数 - “token_type”。 所以问题是:是否可以通过某种方式进行自定义,以便 linkedin API 将通过访问 token 响应返回此参数,或者这只是违反规则并且不会返回此参数?
提前致谢。
最佳答案
我也遇到了同样的问题。根据LinkedIn Docs :
A successful Access Token request will return a JSON object containing the following fields:
- access_token — The access token for the user. This value must be kept secure, as per your agreement to the API Terms of Use.
- expires_in — The number of seconds remaining, from the time it was requested, before the token will expire. Currently, all access tokens are issued with a 60 day lifespan.
他们的回应
{"access_token":"...","expires_in":...}
这违反了标准。
目前我正在使用 Spring Security 5.0.3,为了解决这个问题,我必须对一个类进行 Monkeypatch:
com.nimbusds.oauth2.sdk.token.BearerAccessToken
我不会发布整个类(class),只发布重要部分:
public static BearerAccessToken parse(final JSONObject jsonObject)
throws ParseException {
// Parse and verify type
AccessTokenType tokenType;
try {
tokenType = new AccessTokenType(JSONObjectUtils.getString(jsonObject, "token_type"));
} catch (ParseException ex) {
tokenType = AccessTokenType.BEARER;
}
if (!tokenType.equals(AccessTokenType.BEARER))
throw new ParseException("Token type must be \"Bearer\"");
//...
}
关于oauth - Linkedin OAuth 2.0 访问 token 响应不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48586895/