Search in sources :

Example 1 with RefreshTokenResponseData

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();
}
Also used : RefreshTokenResponseData(com.hyq0719.mktapi.oceanengine.bean.token.RefreshTokenResponseData) RefreshTokenRequest(com.hyq0719.mktapi.oceanengine.bean.token.RefreshTokenRequest) AuthToken(test.auth.bean.AuthToken) ApiException(com.hyq0719.mktapi.common.exception.ApiException)

Aggregations

ApiException (com.hyq0719.mktapi.common.exception.ApiException)1 RefreshTokenRequest (com.hyq0719.mktapi.oceanengine.bean.token.RefreshTokenRequest)1 RefreshTokenResponseData (com.hyq0719.mktapi.oceanengine.bean.token.RefreshTokenResponseData)1 AuthToken (test.auth.bean.AuthToken)1