• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Credentials类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.auth0.android.result.Credentials的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Credentials类属于com.auth0.android.result包,在下文中一共展示了Credentials类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onSuccess

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Override
public void onSuccess(@NonNull Credentials credentials) {
    if (linkSessions) {
        performLink(credentials.getIdToken());
        return;
    }

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(LoginActivity.this, "Log In - Success", Toast.LENGTH_SHORT).show();
        }
    });
    CredentialsManager.saveCredentials(LoginActivity.this, credentials);
    startActivity(new Intent(LoginActivity.this, MainActivity.class));
    finish();
}
 
开发者ID:auth0-samples,项目名称:auth0-android-sample,代码行数:18,代码来源:LoginActivity.java


示例2: shouldRenewAuthWithDelegationIfNotOIDCConformant

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldRenewAuthWithDelegationIfNotOIDCConformant() throws Exception {
    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    auth0.setOIDCConformant(false);
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    mockAPI.willReturnSuccessfulLogin();
    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.renewAuth("refreshToken")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/delegation"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("refresh_token", "refreshToken"));
    assertThat(body, hasEntry("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer"));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:23,代码来源:AuthenticationAPIClientTest.java


示例3: shouldGetOAuthTokensUsingCodeVerifier

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldGetOAuthTokensUsingCodeVerifier() throws Exception {
    mockAPI.willReturnTokens()
            .willReturnTokenInfo();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.token("code", "http://redirect.uri")
            .setCodeVerifier("codeVerifier")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), equalTo("/oauth/token"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE));
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("code", "code"));
    assertThat(body, hasEntry("code_verifier", "codeVerifier"));
    assertThat(body, hasEntry("redirect_uri", "http://redirect.uri"));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:23,代码来源:AuthenticationAPIClientTest.java


示例4: renewAuth

import com.auth0.android.result.Credentials; //导入依赖的package包/类
/**
 * Requests new Credentials using a valid Refresh Token. The received token will have the same audience and scope as first requested. How the new Credentials are requested depends on the {@link Auth0#isOIDCConformant()} flag.
 * - If the instance is OIDC Conformant the endpoint will be /oauth/token with 'refresh_token' grant, and the response will include an id_token and an access_token if 'openid' scope was requested when the refresh_token was obtained.
 * - If the instance is not OIDC Conformant the endpoint will be /delegation with 'urn:ietf:params:oauth:grant-type:jwt-bearer' grant, and the response will include an id_token.
 * Example usage:
 * <pre>
 * {@code
 * client.renewAuth("{refresh_token}")
 *      .addParameter("scope", "openid profile email")
 *      .start(new BaseCallback<Credentials>() {
 *          {@literal}Override
 *          public void onSuccess(Credentials payload) { }
 *
 *          {@literal}@Override
 *          public void onFailure(AuthenticationException error) { }
 *      });
 * }
 * </pre>
 *
 * @param refreshToken used to fetch the new Credentials.
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public ParameterizableRequest<Credentials, AuthenticationException> renewAuth(@NonNull String refreshToken) {
    final Map<String, Object> parameters = ParameterBuilder.newBuilder()
            .setClientId(getClientId())
            .setRefreshToken(refreshToken)
            .setGrantType(auth0.isOIDCConformant() ? ParameterBuilder.GRANT_TYPE_REFRESH_TOKEN : ParameterBuilder.GRANT_TYPE_JWT)
            .asDictionary();

    HttpUrl url;
    if (auth0.isOIDCConformant()) {
        url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
                .addPathSegment(OAUTH_PATH)
                .addPathSegment(TOKEN_PATH)
                .build();
    } else {
        url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder()
                .addPathSegment(DELEGATION_PATH)
                .build();
    }

    return factory.POST(url, client, gson, Credentials.class, authErrorBuilder)
            .addParameters(parameters);
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:46,代码来源:AuthenticationAPIClient.java


示例5: getToken

import com.auth0.android.result.Credentials; //导入依赖的package包/类
/**
 * Performs a request to the Auth0 API to get the OAuth Token and end the PKCE flow.
 * The instance of this class must be disposed after this method is called.
 *
 * @param authorizationCode received in the call to /authorize with a "grant_type=code"
 * @param callback          to notify the result of this call to.
 */
public void getToken(String authorizationCode, @NonNull final AuthCallback callback) {
    apiClient.token(authorizationCode, redirectUri)
            .setCodeVerifier(codeVerifier)
            .start(new BaseCallback<Credentials, AuthenticationException>() {
                @Override
                public void onSuccess(Credentials payload) {
                    callback.onSuccess(payload);
                }

                @Override
                public void onFailure(AuthenticationException error) {
                    if ("Unauthorized".equals(error.getDescription())) {
                        Log.e(TAG, "Please go to 'https://manage.auth0.com/#/applications/" + apiClient.getClientId() + "/settings' and set 'Client Type' to 'Native' to enable PKCE.");
                    }
                    callback.onFailure(error);
                }
            });
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:26,代码来源:PKCE.java


示例6: shouldRenewAuthWithOAuthTokenIfOIDCConformant

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldRenewAuthWithOAuthTokenIfOIDCConformant() throws Exception {
    Auth0 auth0 = new Auth0(CLIENT_ID, mockAPI.getDomain(), mockAPI.getDomain());
    auth0.setOIDCConformant(true);
    AuthenticationAPIClient client = new AuthenticationAPIClient(auth0);

    mockAPI.willReturnSuccessfulLogin();
    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.renewAuth("refreshToken")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/token"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("refresh_token", "refreshToken"));
    assertThat(body, hasEntry("grant_type", "refresh_token"));

    assertThat(callback, hasPayloadOfType(Credentials.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:23,代码来源:AuthenticationAPIClientTest.java


示例7: shouldLoginWithEmailOnlySync

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldLoginWithEmailOnlySync() throws Exception {
    mockAPI
            .willReturnSuccessfulLogin()
            .willReturnTokenInfo();

    final Credentials credentials = client
            .loginWithEmail(SUPPORT_AUTH0_COM, "1234")
            .execute();

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getHeader("Accept-Language"), is(getDefaultLocale()));
    assertThat(request.getPath(), equalTo("/oauth/ro"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("connection", "email"));
    assertThat(body, hasEntry("username", SUPPORT_AUTH0_COM));
    assertThat(body, hasEntry("password", "1234"));
    assertThat(body, hasEntry("scope", OPENID));

    assertThat(credentials, is(notNullValue()));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:23,代码来源:AuthenticationAPIClientTest.java


示例8: shouldSerializeCredentials

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldSerializeCredentials() throws Exception {
    Date expiresAt = new Date(CredentialsMock.CURRENT_TIME_MS + 123456 * 1000);
    final String expectedExpiresAt = GsonProvider.formatDate(expiresAt);

    final Credentials expiresInCredentials = new CredentialsMock("id", "access", "ty", "refresh", 123456L);
    final String expiresInJson = gson.toJson(expiresInCredentials);
    assertThat(expiresInJson, containsString("\"id_token\":\"id\""));
    assertThat(expiresInJson, containsString("\"access_token\":\"access\""));
    assertThat(expiresInJson, containsString("\"token_type\":\"ty\""));
    assertThat(expiresInJson, containsString("\"refresh_token\":\"refresh\""));
    assertThat(expiresInJson, containsString("\"expires_in\":123456"));
    assertThat(expiresInJson, containsString("\"expires_at\":\"" + expectedExpiresAt + "\""));
    assertThat(expiresInJson, not(containsString("\"scope\"")));


    final Credentials expiresAtCredentials = new CredentialsMock("id", "access", "ty", "refresh", expiresAt, "openid");
    final String expiresAtJson = gson.toJson(expiresAtCredentials);
    assertThat(expiresAtJson, containsString("\"id_token\":\"id\""));
    assertThat(expiresAtJson, containsString("\"access_token\":\"access\""));
    assertThat(expiresAtJson, containsString("\"token_type\":\"ty\""));
    assertThat(expiresAtJson, containsString("\"refresh_token\":\"refresh\""));
    assertThat(expiresAtJson, containsString("\"expires_in\":123456"));
    assertThat(expiresInJson, containsString("\"expires_at\":\"" + expectedExpiresAt + "\""));
    assertThat(expiresAtJson, containsString("\"scope\":\"openid\""));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:27,代码来源:CredentialsGsonTest.java


示例9: shouldResumeWithIntentWithImplicitGrant

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void shouldResumeWithIntentWithImplicitGrant() throws Exception {
    WebAuthProvider.init(account)
            .useCodeGrant(false)
            .start(activity, callback);

    verify(activity).startActivity(intentCaptor.capture());
    Uri uri = intentCaptor.getValue().getParcelableExtra(AuthenticationActivity.EXTRA_AUTHORIZE_URI);
    assertThat(uri, is(notNullValue()));

    String sentState = uri.getQueryParameter(KEY_STATE);
    assertThat(sentState, is(not(isEmptyOrNullString())));
    Intent intent = createAuthIntent(createHash("urlId", "urlAccess", "urlRefresh", "urlType", 1111L, sentState, null, null));
    assertTrue(WebAuthProvider.resume(intent));

    ArgumentCaptor<Credentials> credentialsCaptor = ArgumentCaptor.forClass(Credentials.class);
    verify(callback).onSuccess(credentialsCaptor.capture());

    assertThat(credentialsCaptor.getValue(), is(notNullValue()));
    assertThat(credentialsCaptor.getValue().getIdToken(), is("urlId"));
    assertThat(credentialsCaptor.getValue().getAccessToken(), is("urlAccess"));
    assertThat(credentialsCaptor.getValue().getRefreshToken(), is("urlRefresh"));
    assertThat(credentialsCaptor.getValue().getType(), is("urlType"));
    assertThat(credentialsCaptor.getValue().getExpiresIn(), is(1111L));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:27,代码来源:WebAuthProviderTest.java


示例10: shouldParseUnauthorizedPKCEError

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldParseUnauthorizedPKCEError() throws Exception {
    mockAPI
            .willReturnPlainTextUnauthorized();

    final MockAuthenticationCallback<Credentials> callback = new MockAuthenticationCallback<>();
    client.token("code", "http://redirect.uri")
            .setCodeVerifier("codeVerifier")
            .start(callback);

    final RecordedRequest request = mockAPI.takeRequest();
    assertThat(request.getPath(), equalTo("/oauth/token"));

    Map<String, String> body = bodyFromRequest(request);
    assertThat(body, hasEntry("grant_type", ParameterBuilder.GRANT_TYPE_AUTHORIZATION_CODE));
    assertThat(body, hasEntry("client_id", CLIENT_ID));
    assertThat(body, hasEntry("code", "code"));
    assertThat(body, hasEntry("code_verifier", "codeVerifier"));
    assertThat(body, hasEntry("redirect_uri", "http://redirect.uri"));

    assertThat(callback, hasError(Credentials.class));
    assertThat(callback.getError().getDescription(), is(equalTo("Unauthorized")));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:24,代码来源:AuthenticationAPIClientTest.java


示例11: shouldMergeCredentials

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldMergeCredentials() throws Exception {
    Date expiresAt = new Date();
    Credentials urlCredentials = new Credentials("urlId", "urlAccess", "urlType", "urlRefresh", expiresAt, "urlScope");
    Credentials codeCredentials = new Credentials("codeId", "codeAccess", "codeType", "codeRefresh", expiresAt, "codeScope");
    Credentials merged = OAuthManager.mergeCredentials(urlCredentials, codeCredentials);

    assertThat(merged.getIdToken(), is(codeCredentials.getIdToken()));
    assertThat(merged.getAccessToken(), is(codeCredentials.getAccessToken()));
    assertThat(merged.getType(), is(codeCredentials.getType()));
    assertThat(merged.getRefreshToken(), is(codeCredentials.getRefreshToken()));
    assertThat(merged.getExpiresIn(), is(codeCredentials.getExpiresIn()));
    assertThat(merged.getExpiresAt(), is(expiresAt));
    assertThat(merged.getExpiresAt(), is(codeCredentials.getExpiresAt()));
    assertThat(merged.getScope(), is(codeCredentials.getScope()));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:17,代码来源:OAuthManagerTest.java


示例12: shouldResumeWithRequestCodeWithImplicitGrant

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void shouldResumeWithRequestCodeWithImplicitGrant() throws Exception {
    WebAuthProvider.init(account)
            .useCodeGrant(false)
            .start(activity, callback, REQUEST_CODE);

    verify(activity).startActivity(intentCaptor.capture());
    Uri uri = intentCaptor.getValue().getParcelableExtra(AuthenticationActivity.EXTRA_AUTHORIZE_URI);
    assertThat(uri, is(notNullValue()));

    String sentState = uri.getQueryParameter(KEY_STATE);
    assertThat(sentState, is(not(isEmptyOrNullString())));
    Intent intent = createAuthIntent(createHash("urlId", "urlAccess", "urlRefresh", "urlType", 1111L, sentState, null, null));
    assertTrue(WebAuthProvider.resume(REQUEST_CODE, Activity.RESULT_OK, intent));

    ArgumentCaptor<Credentials> credentialsCaptor = ArgumentCaptor.forClass(Credentials.class);
    verify(callback).onSuccess(credentialsCaptor.capture());

    assertThat(credentialsCaptor.getValue(), is(notNullValue()));
    assertThat(credentialsCaptor.getValue().getIdToken(), is("urlId"));
    assertThat(credentialsCaptor.getValue().getAccessToken(), is("urlAccess"));
    assertThat(credentialsCaptor.getValue().getRefreshToken(), is("urlRefresh"));
    assertThat(credentialsCaptor.getValue().getType(), is("urlType"));
    assertThat(credentialsCaptor.getValue().getExpiresIn(), is(1111L));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:27,代码来源:WebAuthProviderTest.java


示例13: shouldReturnErrorAfterStartingTheRequestIfTokenInfoRequestFails

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldReturnErrorAfterStartingTheRequestIfTokenInfoRequestFails() throws Exception {
    final Credentials credentials = mock(Credentials.class);
    final AuthenticationException error = mock(AuthenticationException.class);

    final AuthenticationRequestMock authenticationRequestMock = new AuthenticationRequestMock(credentials, null);
    final ParameterizableRequestMock tokenInfoRequestMock = new ParameterizableRequestMock(null, error);
    final BaseCallback callback = mock(BaseCallback.class);

    profileRequest = new ProfileRequest(authenticationRequestMock, tokenInfoRequestMock);
    profileRequest.start(callback);

    assertTrue(authenticationRequestMock.isStarted());
    assertTrue(tokenInfoRequestMock.isStarted());

    verify(callback).onFailure(error);
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:18,代码来源:ProfileRequestTest.java


示例14: shouldSaveRefreshableCredentialsInStorage

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldSaveRefreshableCredentialsInStorage() throws Exception {
    long expirationTime = CredentialsMock.CURRENT_TIME_MS + 123456 * 1000;
    Credentials credentials = new CredentialsMock("idToken", "accessToken", "type", "refreshToken", new Date(expirationTime), "scope");
    String json = gson.toJson(credentials);
    when(crypto.encrypt(json.getBytes())).thenReturn(json.getBytes());

    manager.saveCredentials(credentials);

    verify(storage).store(eq("com.auth0.credentials"), stringCaptor.capture());
    verify(storage).store("com.auth0.credentials_expires_at", expirationTime);
    verify(storage).store("com.auth0.credentials_can_refresh", true);
    verifyNoMoreInteractions(storage);
    final String encodedJson = stringCaptor.getValue();
    assertThat(encodedJson, is(notNullValue()));
    final byte[] decoded = Base64.decode(encodedJson, Base64.DEFAULT);
    Credentials storedCredentials = gson.fromJson(new String(decoded), Credentials.class);
    assertThat(storedCredentials.getAccessToken(), is("accessToken"));
    assertThat(storedCredentials.getIdToken(), is("idToken"));
    assertThat(storedCredentials.getRefreshToken(), is("refreshToken"));
    assertThat(storedCredentials.getType(), is("type"));
    assertThat(storedCredentials.getExpiresAt(), is(notNullValue()));
    assertThat(storedCredentials.getExpiresAt().getTime(), is(expirationTime));
    assertThat(storedCredentials.getScope(), is("scope"));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:26,代码来源:SecureCredentialsManagerTest.java


示例15: shouldSaveNonRefreshableCredentialsInStorage

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldSaveNonRefreshableCredentialsInStorage() throws Exception {
    long expirationTime = CredentialsMock.CURRENT_TIME_MS + 123456 * 1000;
    Credentials credentials = new CredentialsMock("idToken", "accessToken", "type", null, new Date(expirationTime), "scope");
    String json = gson.toJson(credentials);
    when(crypto.encrypt(json.getBytes())).thenReturn(json.getBytes());

    manager.saveCredentials(credentials);

    verify(storage).store(eq("com.auth0.credentials"), stringCaptor.capture());
    verify(storage).store("com.auth0.credentials_expires_at", expirationTime);
    verify(storage).store("com.auth0.credentials_can_refresh", false);
    verifyNoMoreInteractions(storage);
    final String encodedJson = stringCaptor.getValue();
    assertThat(encodedJson, is(notNullValue()));
    final byte[] decoded = Base64.decode(encodedJson, Base64.DEFAULT);
    Credentials storedCredentials = gson.fromJson(new String(decoded), Credentials.class);
    assertThat(storedCredentials.getAccessToken(), is("accessToken"));
    assertThat(storedCredentials.getIdToken(), is("idToken"));
    assertThat(storedCredentials.getRefreshToken(), is(nullValue()));
    assertThat(storedCredentials.getType(), is("type"));
    assertThat(storedCredentials.getExpiresAt(), is(notNullValue()));
    assertThat(storedCredentials.getExpiresAt().getTime(), is(expirationTime));
    assertThat(storedCredentials.getScope(), is("scope"));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:26,代码来源:SecureCredentialsManagerTest.java


示例16: shouldResumeWithRequestCodeWithResponseTypeIdToken

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void shouldResumeWithRequestCodeWithResponseTypeIdToken() throws Exception {
    WebAuthProvider.init(account)
            .withResponseType(ResponseType.ID_TOKEN)
            .start(activity, callback, REQUEST_CODE);

    verify(activity).startActivity(intentCaptor.capture());
    Uri uri = intentCaptor.getValue().getParcelableExtra(AuthenticationActivity.EXTRA_AUTHORIZE_URI);
    assertThat(uri, is(notNullValue()));

    String sentState = uri.getQueryParameter(KEY_STATE);
    String sentNonce = uri.getQueryParameter(KEY_NONCE);
    assertThat(sentState, is(not(isEmptyOrNullString())));
    assertThat(sentNonce, is(not(isEmptyOrNullString())));
    Intent intent = createAuthIntent(createHash(customNonceJWT(sentNonce), null, null, null, null, sentState, null, null));
    assertTrue(WebAuthProvider.resume(REQUEST_CODE, Activity.RESULT_OK, intent));

    verify(callback).onSuccess(any(Credentials.class));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:21,代码来源:WebAuthProviderTest.java


示例17: shouldFailOnGetCredentialsWhenNoAccessTokenOrIdTokenWasSaved

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldFailOnGetCredentialsWhenNoAccessTokenOrIdTokenWasSaved() throws Exception {
    verifyNoMoreInteractions(client);

    long expirationTime = CredentialsMock.CURRENT_TIME_MS + 123456L * 1000;
    Credentials storedCredentials = new Credentials(null, null, "type", "refreshToken", new Date(expirationTime), "scope");
    String storedJson = gson.toJson(storedCredentials);
    String encoded = new String(Base64.encode(storedJson.getBytes(), Base64.DEFAULT));
    when(crypto.decrypt(storedJson.getBytes())).thenReturn(storedJson.getBytes());
    when(storage.retrieveString("com.auth0.credentials")).thenReturn(encoded);

    manager.getCredentials(callback);

    verify(callback).onFailure(exceptionCaptor.capture());
    CredentialsManagerException exception = exceptionCaptor.getValue();
    assertThat(exception, is(notNullValue()));
    assertThat(exception.getMessage(), is("No Credentials were previously set."));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:19,代码来源:SecureCredentialsManagerTest.java


示例18: shouldFailOnGetCredentialsWhenNoExpirationTimeWasSaved

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldFailOnGetCredentialsWhenNoExpirationTimeWasSaved() throws Exception {
    verifyNoMoreInteractions(client);

    Date expiresAt = null;
    Credentials storedCredentials = new Credentials("idToken", "accessToken", "type", "refreshToken", expiresAt, "scope");
    String storedJson = gson.toJson(storedCredentials);
    String encoded = new String(Base64.encode(storedJson.getBytes(), Base64.DEFAULT));
    when(crypto.decrypt(storedJson.getBytes())).thenReturn(storedJson.getBytes());
    when(storage.retrieveString("com.auth0.credentials")).thenReturn(encoded);

    manager.getCredentials(callback);

    verify(callback).onFailure(exceptionCaptor.capture());
    CredentialsManagerException exception = exceptionCaptor.getValue();
    assertThat(exception, is(notNullValue()));
    assertThat(exception.getMessage(), is("No Credentials were previously set."));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:19,代码来源:SecureCredentialsManagerTest.java


示例19: shouldFailOnGetCredentialsWhenExpiredAndNoRefreshTokenWasSaved

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@SuppressWarnings("UnnecessaryLocalVariable")
@Test
public void shouldFailOnGetCredentialsWhenExpiredAndNoRefreshTokenWasSaved() throws Exception {
    verifyNoMoreInteractions(client);

    Date expiresAt = new Date(CredentialsMock.CURRENT_TIME_MS); //Same as current time --> expired
    Credentials storedCredentials = new Credentials("idToken", "accessToken", "type", null, expiresAt, "scope");
    when(storage.retrieveLong("com.auth0.credentials_expires_at")).thenReturn(expiresAt.getTime());
    when(storage.retrieveBoolean("com.auth0.credentials_can_refresh")).thenReturn(false);
    String storedJson = gson.toJson(storedCredentials);
    String encoded = new String(Base64.encode(storedJson.getBytes(), Base64.DEFAULT));
    when(crypto.decrypt(storedJson.getBytes())).thenReturn(storedJson.getBytes());
    when(storage.retrieveString("com.auth0.credentials")).thenReturn(encoded);

    manager.getCredentials(callback);

    verify(callback).onFailure(exceptionCaptor.capture());
    CredentialsManagerException exception = exceptionCaptor.getValue();
    assertThat(exception, is(notNullValue()));
    assertThat(exception.getMessage(), is("No Credentials were previously set."));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:22,代码来源:SecureCredentialsManagerTest.java


示例20: shouldGetNonExpiredCredentialsFromStorage

import com.auth0.android.result.Credentials; //导入依赖的package包/类
@Test
public void shouldGetNonExpiredCredentialsFromStorage() throws Exception {
    verifyNoMoreInteractions(client);

    Date expiresAt = new Date(CredentialsMock.CURRENT_TIME_MS + 123456L * 1000);
    Credentials storedCredentials = new Credentials("idToken", "accessToken", "type", "refreshToken", expiresAt, "scope");
    String storedJson = gson.toJson(storedCredentials);
    String encoded = new String(Base64.encode(storedJson.getBytes(), Base64.DEFAULT));
    when(crypto.decrypt(storedJson.getBytes())).thenReturn(storedJson.getBytes());
    when(storage.retrieveString("com.auth0.credentials")).thenReturn(encoded);
    when(storage.retrieveLong("com.auth0.credentials_expires_at")).thenReturn(expiresAt.getTime());
    when(storage.retrieveBoolean("com.auth0.credentials_can_refresh")).thenReturn(false);

    manager.getCredentials(callback);
    verify(callback).onSuccess(credentialsCaptor.capture());
    Credentials retrievedCredentials = credentialsCaptor.getValue();

    assertThat(retrievedCredentials, is(notNullValue()));
    assertThat(retrievedCredentials.getAccessToken(), is("accessToken"));
    assertThat(retrievedCredentials.getIdToken(), is("idToken"));
    assertThat(retrievedCredentials.getRefreshToken(), is("refreshToken"));
    assertThat(retrievedCredentials.getType(), is("type"));
    assertThat(retrievedCredentials.getExpiresAt(), is(notNullValue()));
    assertThat(retrievedCredentials.getExpiresAt().getTime(), is(expiresAt.getTime()));
    assertThat(retrievedCredentials.getScope(), is("scope"));
}
 
开发者ID:auth0,项目名称:Auth0.Android,代码行数:27,代码来源:SecureCredentialsManagerTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PolymorphismType类代码示例发布时间:2022-05-23
下一篇:
Java Key类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap