@Override public void signRequest(Request.Builder builder) { if(tokenStorage.getAccessToken() != null && tokenStorage.getAccessToken().getToken() != null) { setBearerToken(builder, tokenStorage.getAccessToken()); } }
protected synchronized Request doRefresh(Response response) throws IOException { final AccessToken token = tokenStorage.getAccessToken(); if (signedByOldToken(response, token)) { return resign(response, token); } else { return refreshAndSign(response, token); } }
@Override public boolean isRefreshable() { return tokenStorage.getAccessToken() != null && tokenStorage.getAccessToken().getRefreshToken() != null; }
@Override public final Request refresh(Response response) throws IOException { if (isRefreshable() && canRefresh(response) && canRetry(response)) { return doRefresh(response); } return null; }
@Test public void getAuthorizationUrl_whenThereAreNoScopes() throws Exception { OAuth2Credentials oAuth2Credentials = new OAuth2Credentials.Builder() .setClientSecrets("CLIENT_ID", "CLIENT_SECRET") .build(); assertEquals("https://login.uber.com/oauth/v2/authorize?client_id=CLIENT_ID&response_type=code", oAuth2Credentials.getAuthorizationUrl()); }
Request refreshAndSign(Response response, AccessToken auth2Token) throws IOException { AccessToken token = refreshToken(auth2Token); return resign(response, token); }
@Test public void testIsRefreshable_validToken_returnsTrue() throws Exception { when(accessTokenStorage.getAccessToken()).thenReturn(accessToken); when(accessToken.getRefreshToken()).thenReturn("refreshToken"); assertTrue(authenticator.isRefreshable()); }
@Override public Request authenticate(Route route, Response response) throws IOException { return authenticator.refresh(response); } }
@Override protected Request doRefresh(Response response) throws IOException { if (signedByOldToken(response, credential)) { return resign(response, credential); } else { return refreshAndSign(response, credential); } }
/** * @param config to define connection parameters */ public ServerTokenSession(@Nonnull SessionConfiguration config) { super(new ServerTokenAuthenticator(config)); } }
@Override public LowLevelHttpResponse execute() throws IOException { lastRequestUrl = getUrl(); lastRequestContent = getContentAsString(); MockLowLevelHttpResponse mock = new MockLowLevelHttpResponse(); mock.setStatusCode(httpStatusCode); mock.setContent(httpResponseContent); return mock; } };
@Override public void signRequest(Request.Builder builder) { setBearerToken(builder, credential); }
/** * @param config config to define connection parameters * @param credential to access and refresh token */ public CredentialsSession(@Nonnull SessionConfiguration config, @Nonnull Credential credential) { super(new CredentialsAuthenticator(config, credential)); } }
/** * Loads the Credential for the user from the underlying {@link DataStore}. * @throws AuthException If the credential could not be loaded. */ public Credential loadCredential(String userId) throws AuthException { try { return authorizationCodeFlow.loadCredential(userId); } catch (IOException e) { throw new AuthException("Unable to load credential.", e); } }
protected synchronized Request doRefresh(Response response) throws IOException { final AccessToken token = tokenStorage.getAccessToken(); if (signedByOldToken(response, token)) { return resign(response, token); } else { return refreshAndSign(response, token); } }
@Override public final Request refresh(Response response) throws IOException { if (isRefreshable() && canRefresh(response) && canRetry(response)) { return doRefresh(response); } return null; }
@Override public void signRequest(Request.Builder builder) { if(tokenStorage.getAccessToken() != null && tokenStorage.getAccessToken().getToken() != null) { setBearerToken(builder, tokenStorage.getAccessToken()); } }
@Override public boolean isRefreshable() { return tokenStorage.getAccessToken() != null && tokenStorage.getAccessToken().getRefreshToken() != null; }
Request refreshAndSign(Response response, AccessToken auth2Token) throws IOException { AccessToken token = refreshToken(auth2Token); return resign(response, token); }
@Override public Request authenticate(Route route, Response response) throws IOException { return authenticator.refresh(response); } }