25 lines
1.0 KiB
Java
25 lines
1.0 KiB
Java
|
|
package com.baeldung.oauth2;
|
||
|
|
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
import org.springframework.core.convert.converter.Converter;
|
||
|
|
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
|
||
|
|
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
|
||
|
|
|
||
|
|
public class LinkedinTokenResponseConverter implements Converter<Map<String, String>, OAuth2AccessTokenResponse> {
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public OAuth2AccessTokenResponse convert(Map<String, String> tokenResponseParameters) {
|
||
|
|
String accessToken = tokenResponseParameters.get(OAuth2ParameterNames.ACCESS_TOKEN);
|
||
|
|
long expiresIn = Long.valueOf(tokenResponseParameters.get(OAuth2ParameterNames.EXPIRES_IN));
|
||
|
|
|
||
|
|
OAuth2AccessToken.TokenType accessTokenType = OAuth2AccessToken.TokenType.BEARER;
|
||
|
|
|
||
|
|
return OAuth2AccessTokenResponse.withToken(accessToken)
|
||
|
|
.tokenType(accessTokenType)
|
||
|
|
.expiresIn(expiresIn)
|
||
|
|
.build();
|
||
|
|
}
|
||
|
|
}
|