use of com.hyq0719.mktapi.oceanengine.bean.token.RefreshTokenResponseData in project marketing-api-java-sdks by Hyq0719.
the class OceanAuthorizer method refresh.
@Override
public Result<AuthToken> refresh(AuthToken authToken) {
OceanProperties.OceanOAuth2Config config = oceanProperties.getConfigs().get(authToken.getAdvertiserId());
if (config == null) {
return Result.ofFail();
}
if (isDebugMode()) {
return Util.refreshForTest(authToken);
}
RefreshTokenRequest request = new RefreshTokenRequest();
request.appId(Long.valueOf(config.getClientId())).secret(config.getSecret()).refreshToken(authToken.getRefreshToken()).grantType("auth_code");
try {
OceanResponse<RefreshTokenResponseData> response = oceanSdkService.getTokenApi().refreshToken().execute(request);
if (!response.isSuccessful()) {
return Result.ofFail();
}
RefreshTokenResponseData data = response.getData();
AuthToken newAuthToken = authToken.newToken(data.getAccessToken(), data.getRefreshToken());
return Result.ofSuccessful(newAuthToken);
} catch (ApiException e) {
e.printStackTrace();
}
return Result.ofFail();
}
Aggregations