当前位置: 首页>>代码示例>>Java>>正文


Java BaseCallback.onSuccess方法代码示例

本文整理汇总了Java中com.auth0.android.callback.BaseCallback.onSuccess方法的典型用法代码示例。如果您正苦于以下问题:Java BaseCallback.onSuccess方法的具体用法?Java BaseCallback.onSuccess怎么用?Java BaseCallback.onSuccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.auth0.android.callback.BaseCallback的用法示例。


在下文中一共展示了BaseCallback.onSuccess方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCredentials

import com.auth0.android.callback.BaseCallback; //导入方法依赖的package包/类
/**
 * Retrieves the credentials from the storage and refresh them if they have already expired.
 * It will fail with {@link CredentialsManagerException} if the saved access_token or id_token is null,
 * or if the tokens have already expired and the refresh_token is null.
 *
 * @param callback the callback that will receive a valid {@link Credentials} or the {@link CredentialsManagerException}.
 */
public void getCredentials(@NonNull final BaseCallback<Credentials, CredentialsManagerException> callback) {
    String accessToken = storage.retrieveString(KEY_ACCESS_TOKEN);
    final String refreshToken = storage.retrieveString(KEY_REFRESH_TOKEN);
    String idToken = storage.retrieveString(KEY_ID_TOKEN);
    String tokenType = storage.retrieveString(KEY_TOKEN_TYPE);
    Long expiresAt = storage.retrieveLong(KEY_EXPIRES_AT);
    String scope = storage.retrieveString(KEY_SCOPE);

    if (isEmpty(accessToken) && isEmpty(idToken) || expiresAt == null) {
        callback.onFailure(new CredentialsManagerException("No Credentials were previously set."));
        return;
    }
    if (expiresAt > getCurrentTimeInMillis()) {
        callback.onSuccess(recreateCredentials(idToken, accessToken, tokenType, refreshToken, new Date(expiresAt), scope));
        return;
    }
    if (refreshToken == null) {
        callback.onFailure(new CredentialsManagerException("Credentials have expired and no Refresh Token was available to renew them."));
        return;
    }

    authClient.renewAuth(refreshToken).start(new AuthenticationCallback<Credentials>() {
        @Override
        public void onSuccess(Credentials fresh) {
            //RefreshTokens don't expire. It should remain the same
            Credentials credentials = new Credentials(fresh.getIdToken(), fresh.getAccessToken(), fresh.getType(), refreshToken, fresh.getExpiresAt(), fresh.getScope());
            saveCredentials(credentials);
            callback.onSuccess(credentials);
        }

        @Override
        public void onFailure(AuthenticationException error) {
            callback.onFailure(new CredentialsManagerException("An error occurred while trying to use the Refresh Token to renew the Credentials.", error));
        }
    });
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:44,代码来源:CredentialsManager.java

示例2: start

import com.auth0.android.callback.BaseCallback; //导入方法依赖的package包/类
@Override
public void start(BaseCallback<Credentials, AuthenticationException> callback) {
    started = true;
    if (credentials != null) {
        callback.onSuccess(credentials);
    } else {
        callback.onFailure(error);
    }
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:10,代码来源:AuthenticationRequestMock.java

示例3: start

import com.auth0.android.callback.BaseCallback; //导入方法依赖的package包/类
@Override
public void start(BaseCallback<T, U> callback) {
    started = true;
    if (payload != null) {
        callback.onSuccess(payload);
    } else {
        callback.onFailure(error);
    }
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:10,代码来源:ParameterizableRequestMock.java

示例4: start

import com.auth0.android.callback.BaseCallback; //导入方法依赖的package包/类
@Override
public void start(BaseCallback callback) {
    this.started = true;
    if (payload != null) {
        callback.onSuccess(payload);
    } else {
        callback.onFailure(error);
    }
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:10,代码来源:DatabaseConnectionRequestMock.java

示例5: continueGetCredentials

import com.auth0.android.callback.BaseCallback; //导入方法依赖的package包/类
private void continueGetCredentials(final BaseCallback<Credentials, CredentialsManagerException> callback) {
    String encryptedEncoded = storage.retrieveString(KEY_CREDENTIALS);
    byte[] encrypted = Base64.decode(encryptedEncoded, Base64.DEFAULT);

    String json;
    try {
        json = new String(crypto.decrypt(encrypted));
    } catch (CryptoException e) {
        callback.onFailure(new CredentialsManagerException("An error occurred while decrypting the existing credentials.", e));
        return;
    }
    final Credentials credentials = gson.fromJson(json, Credentials.class);
    if (isEmpty(credentials.getAccessToken()) && isEmpty(credentials.getIdToken()) || credentials.getExpiresAt() == null) {
        callback.onFailure(new CredentialsManagerException("No Credentials were previously set."));
        decryptCallback = null;
        return;
    }
    if (credentials.getExpiresAt().getTime() > getCurrentTimeInMillis()) {
        callback.onSuccess(credentials);
        decryptCallback = null;
        return;
    }
    if (credentials.getRefreshToken() == null) {
        callback.onFailure(new CredentialsManagerException("No Credentials were previously set."));
        decryptCallback = null;
        return;
    }

    Log.d(TAG, "Credentials have expired. Renewing them now...");
    apiClient.renewAuth(credentials.getRefreshToken()).start(new AuthenticationCallback<Credentials>() {
        @Override
        public void onSuccess(Credentials fresh) {
            //RefreshTokens don't expire. It should remain the same
            Credentials refreshed = new Credentials(fresh.getIdToken(), fresh.getAccessToken(), fresh.getType(), credentials.getRefreshToken(), fresh.getExpiresAt(), fresh.getScope());
            saveCredentials(refreshed);
            callback.onSuccess(refreshed);
            decryptCallback = null;
        }

        @Override
        public void onFailure(AuthenticationException error) {
            callback.onFailure(new CredentialsManagerException("An error occurred while trying to use the Refresh Token to renew the Credentials.", error));
            decryptCallback = null;
        }
    });
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:47,代码来源:SecureCredentialsManager.java


注:本文中的com.auth0.android.callback.BaseCallback.onSuccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。