public void launchInBrowser( String browser, String redirectUrl, String clientId, String scope) throws IOException { String authorizationUrl = new AuthorizationCodeRequestUrl( AUTHORIZATION_SERVER_URL, clientId).setRedirectUri(redirectUrl) .setScopes(Arrays.asList(scope)).build(); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { desktop.browse(URI.create(authorizationUrl)); return; } } if (browser != null) { Runtime.getRuntime().exec(new String[] {browser, authorizationUrl}); } else { System.out.println("Open the following address in your favorite browser:"); System.out.println(" " + authorizationUrl); } }
public void launchInBrowser( String browser, String redirectUrl, String clientId, String scope) throws IOException { String authorizationUrl = new AuthorizationCodeRequestUrl( AUTHORIZATION_SERVER_URL, clientId).setRedirectUri(redirectUrl) .setScopes(Arrays.asList(scope)).build(); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Action.BROWSE)) { desktop.browse(URI.create(authorizationUrl)); return; } } if (browser != null) { Runtime.getRuntime().exec(new String[] {browser, authorizationUrl}); } else { System.out.println("Open the following address in your favorite browser:"); System.out.println(" " + authorizationUrl); } }
/** * Returns a URL where the user should be redirected in order to authorize access to the selected resources. * @return the authorization URL. */ public String computeAuthorizationUrl() { String redirectUri = getRedirectUrl(); String authorizationUrl = new AuthorizationCodeRequestUrl(authorizationServerUrl, clientId) .setRedirectUri(redirectUri) .setScopes(scopes).build(); return authorizationUrl; }
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); } }
new AuthorizationCodeRequestUrl( GoogleOAuthConstants.AUTHORIZATION_SERVER_URL, clientInfo.getId()) .setRedirectUri(redirectUrl)