builder.setDataStoreFactory(credentialDataStoreFactory).build(); } catch (IOException e) { throw new IllegalStateException("Unexpected exception while building OAuth2Credentials.", e);
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); } }
authorizationServerUrl) .setScopes(scopes) .build(); final AuthorizationCodeRequestUrl authorizationCodeRequestUrl = flow.newAuthorizationUrl(); authorizationCodeRequestUrl.setRedirectUri(redirectUri);
.setDataStoreFactory(dataStoreFactory) .setScopes(scopes) .build();
@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(); }
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 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); }
protected AuthorizationCodeFlow createCodeFlow() { return new AuthorizationCodeFlow.Builder( accessMethod, httpTransport, JSON_FACTORY, new GenericUrl(tokenServerUrl), getHttpExecuteInterceptor(), clientId, authorizationServerUrl) .setScopes(scopes) .setCredentialStore(credentialStore) .build(); }
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(); }