/** * Creates a {@link Credential} objects with the given {@link TokensAndUrlAuthData} which supports * refreshing tokens. */ public Credential createCredential(TokensAndUrlAuthData authData) { return new Credential.Builder(BearerToken.authorizationHeaderAccessMethod()) .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setClientAuthentication( new ClientParametersAuthentication(appCredentials.getKey(), appCredentials.getSecret())) .setTokenServerEncodedUrl(authData.getTokenServerEncodedUrl()) .build() .setAccessToken(authData.getAccessToken()) .setRefreshToken(authData.getRefreshToken()) .setExpiresInSeconds(EXPIRE_TIME_IN_SECONDS); } }
protected HttpExecuteInterceptor getHttpExecuteInterceptor() { return new ClientParametersAuthentication(clientId, clientSecret); }
/** * Sets the client identifier and secret. * * <p> * Overriding is only supported for the purpose of calling the super implementation and changing * the return type, but nothing else. * </p> */ public Builder setClientSecrets(String clientId, String clientSecret) { setClientAuthentication(new ClientParametersAuthentication(clientId, clientSecret)); return this; }
/** * Returns a HTTP execute interceptor with only the client identifier as a * request parameter. * @return HTTP execute interceptor */ protected HttpExecuteInterceptor getClientParameters() { // Sets only the client identifier that is required in authorization // requests. return new ClientParametersAuthentication(credentials.getId(), null); }
/** * @param transport HTTP transport * @param jsonFactory JSON factory * @param refreshToken refresh token issued to the client * @param clientId client identifier issued to the client during the registration process * @param clientSecret client secret */ public GoogleRefreshTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String refreshToken, String clientId, String clientSecret) { super(transport, jsonFactory, new GenericUrl(GoogleOAuthConstants.TOKEN_SERVER_URL), refreshToken); setClientAuthentication(new ClientParametersAuthentication(clientId, clientSecret)); }
/** * * @param transport HTTP transport * @param jsonFactory JSON factory * @param clientId client identifier * @param clientSecret client secret * @param scopes collection of scopes to be joined by a space separator (or a single value * containing multiple space-separated scopes) * * @since 1.15 */ public Builder(HttpTransport transport, JsonFactory jsonFactory, String clientId, String clientSecret, Collection<String> scopes) { super(BearerToken.authorizationHeaderAccessMethod(), transport, jsonFactory, new GenericUrl( GoogleOAuthConstants.TOKEN_SERVER_URL), new ClientParametersAuthentication( clientId, clientSecret), clientId, GoogleOAuthConstants.AUTHORIZATION_SERVER_URL); setScopes(scopes); }
/** * @param transport HTTP transport * @param jsonFactory JSON factory * @param tokenServerEncodedUrl token server encoded URL * @param clientId client identifier issued to the client during the registration process * @param clientSecret client secret * @param code authorization code generated by the authorization server * @param redirectUri redirect URL parameter matching the redirect URL parameter in the * authorization request (see {@link #setRedirectUri(String)} * * @since 1.12 */ public GoogleAuthorizationCodeTokenRequest(HttpTransport transport, JsonFactory jsonFactory, String tokenServerEncodedUrl, String clientId, String clientSecret, String code, String redirectUri) { super(transport, jsonFactory, new GenericUrl(tokenServerEncodedUrl), code); setClientAuthentication(new ClientParametersAuthentication(clientId, clientSecret)); setRedirectUri(redirectUri); }
/** * Sets the client secrets. * * <p> * Overriding is only supported for the purpose of calling the super implementation and changing * the return type, but nothing else. * </p> */ public Builder setClientSecrets(GoogleClientSecrets clientSecrets) { Details details = clientSecrets.getDetails(); setClientAuthentication( new ClientParametersAuthentication(details.getClientId(), details.getClientSecret())); return this; }
JSON_FACTORY, new GenericUrl(TOKEN_SERVER_URL), new ClientParametersAuthentication( API_KEY, API_SECRET), API_KEY,
new JacksonFactory(), new GenericUrl(loginHost + TOKEN_PATH), new ClientParametersAuthentication(clientId, clientSecret), clientId, loginHost + AUTHORIZATION_PATH);
public Credential authorize() { String authorizationUrl = new AuthorizationCodeRequestUrl(AUTHORIZATION_SERVER_URL, OAuth2ClientCredentials.CLIENT_ID).setRedirectUri(URN_IETF_WG_OAUTH_2_0_OOB).setScopes(SCOPES).build(); System.out.println("Please point your browser to the following URL and copy the access token provided after having authorized this application to access your Google Drive:"); System.out.println(authorizationUrl); String code = readCode(); AuthorizationCodeFlow codeFlow = new AuthorizationCodeFlow.Builder( BearerToken.authorizationHeaderAccessMethod(), HTTP_TRANSPORT, JSON_FACTORY, new GenericUrl( TOKEN_SERVER_URL), new ClientParametersAuthentication(OAuth2ClientCredentials.CLIENT_ID, OAuth2ClientCredentials.CLIENT_SECRET), OAuth2ClientCredentials.CLIENT_ID, AUTHORIZATION_SERVER_URL ).setScopes(SCOPES).build(); try { TokenResponse response = codeFlow.newTokenRequest(code).setScopes(SCOPES).setRedirectUri(URN_IETF_WG_OAUTH_2_0_OOB).execute(); return codeFlow.createAndStoreCredential(response, null); } catch (IOException e) { throw new JDriveSyncException(JDriveSyncException.Reason.IOException, "Failed to execute token request and store credentials: " + e.getMessage(), e); } }
public AuthorizationCodeFlow getAuthorizationCodeFlow() { Credential.AccessMethod method = BearerToken.authorizationHeaderAccessMethod(); GenericUrl tokenServerUrl = new GenericUrl(tokenServerURL); HttpExecuteInterceptor clientAuthentication = new ClientParametersAuthentication(clientId, clientSecret); String authorizationServerUrl = authorizationServerURL; return new AuthorizationCodeFlow.Builder(method, HTTP_TRANSPORT, JSON_FACTORY, tokenServerUrl, clientAuthentication, clientId, authorizationServerUrl).setScopes(scopes) .setCredentialDataStore(getCredentialDataStore()) .build(); }
password ).setClientAuthentication( new ClientParametersAuthentication( oauth2.getOauth2ClientID(), oauth2.getOauth2ClientSecret()
public Credential authorize(VerificationCodeReceiver receiver, String redirectUri) throws IOException { String code = receiver.waitForCode(); AuthorizationCodeFlow codeFlow = new AuthorizationCodeFlow.Builder( BearerToken.authorizationHeaderAccessMethod(), HTTP_TRANSPORT, JSON_FACTORY, new GenericUrl(TOKEN_SERVER_URL), new ClientParametersAuthentication( OAuth2ClientCredentials.CLIENT_ID, OAuth2ClientCredentials.CLIENT_SECRET), OAuth2ClientCredentials.CLIENT_ID, AUTHORIZATION_SERVER_URL).setScopes(SCOPE).build(); TokenResponse response = codeFlow.newTokenRequest(code) .setRedirectUri(redirectUri).setScopes(SCOPE).execute(); return codeFlow.createAndStoreCredential(response, null); }
JSON_FACTORY, new GenericUrl(tokenServerUrl), new ClientParametersAuthentication( clientId, clientSecret.getPlainText()
public Credential authorize(VerificationCodeReceiver receiver, String redirectUri) throws IOException { String code = receiver.waitForCode(); AuthorizationCodeFlow codeFlow = new AuthorizationCodeFlow.Builder( BearerToken.authorizationHeaderAccessMethod(), HTTP_TRANSPORT, JSON_FACTORY, new GenericUrl(TOKEN_SERVER_URL), new ClientParametersAuthentication( BaseCloudExample.getAPIKey(), BaseCloudExample.getAPISecret()), BaseCloudExample.getAPIKey(), AUTHORIZATION_SERVER_URL).setScopes(SCOPES).build(); TokenResponse response = codeFlow.newTokenRequest(code) .setRedirectUri(redirectUri).setScopes(SCOPES).execute(); return codeFlow.createAndStoreCredential(response, null); }
public OAuthTokens refresh(final OAuthTokens tokens) throws BackgroundException { if(StringUtils.isBlank(tokens.getRefreshToken())) { log.warn("Missing refresh token"); return tokens; } if(log.isDebugEnabled()) { log.debug(String.format("Refresh expired tokens %s", tokens)); } try { final TokenResponse response = new RefreshTokenRequest(transport, json, new GenericUrl(tokenServerUrl), tokens.getRefreshToken()) .setClientAuthentication(new ClientParametersAuthentication(clientid, clientsecret)) .executeUnparsed().parseAs(PermissiveTokenResponse.class).toTokenResponse(); final long expiryInMilliseconds = System.currentTimeMillis() + response.getExpiresInSeconds() * 1000; if(StringUtils.isBlank(response.getRefreshToken())) { return new OAuthTokens(response.getAccessToken(), tokens.getRefreshToken(), expiryInMilliseconds); } return new OAuthTokens(response.getAccessToken(), response.getRefreshToken(), expiryInMilliseconds); } catch(TokenResponseException e) { throw new OAuthExceptionMappingService().map(e); } catch(HttpResponseException e) { throw new HttpResponseExceptionMappingService().map(new org.apache.http.client .HttpResponseException(e.getStatusCode(), e.getStatusMessage())); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
/** * @param transport HTTP transport * @param jsonFactory JSON factory * @param clientSecrets Google client secrets * @param scopes collection of scopes to be joined by a space separator * * @since 1.15 */ public Builder(HttpTransport transport, JsonFactory jsonFactory, GoogleClientSecrets clientSecrets, Collection<String> scopes) { super(BearerToken.authorizationHeaderAccessMethod(), transport, jsonFactory, new GenericUrl( GoogleOAuthConstants.TOKEN_SERVER_URL), new ClientParametersAuthentication( clientSecrets.getDetails().getClientId(), clientSecrets.getDetails().getClientSecret()), clientSecrets.getDetails().getClientId(), GoogleOAuthConstants.AUTHORIZATION_SERVER_URL); setScopes(scopes); }
@Override public AuthorizationCodeFlow getAuthorizationCodeFlow() { Optional<String> businessResource = getOneDriveForBusinessResource(); if (businessResource.isPresent()) { String clientId = getClientId(); String clientSecret = getClientSecret(); String authorizationServerURL = getAuthorizationServerURL(); Credential.AccessMethod method = BearerToken.authorizationHeaderAccessMethod(); GenericUrl tokenServerUrl = new GenericUrl(getTokenServerURL()); HttpExecuteInterceptor clientAuthentication = new ClientParametersAuthentication(clientId, clientSecret); return new OneDriveAuthorizationCodeFlow.Builder(method, HTTP_TRANSPORT, JSON_FACTORY, tokenServerUrl, clientAuthentication, clientId, authorizationServerURL).setBusinessResource(businessResource.get()) .setScopes(getScopes()) .setCredentialDataStore( getCredentialDataStore()) .build(); } return super.getAuthorizationCodeFlow(); }
transport, json, new GenericUrl(tokenServerUrl), new ClientParametersAuthentication(clientid, clientsecret), clientid, authorizationServerUrl)