Java Code Examples for com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl#build()

The following examples show how to use com.google.api.client.auth.oauth2.AuthorizationCodeRequestUrl#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomAuthorizationCodeInstalledApp.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
protected void onAuthorization( AuthorizationCodeRequestUrl authorizationUrl ) throws IOException {
  String url = authorizationUrl.build();
  Spoon spoon = Spoon.getInstance();
  if ( spoon != null ) {

    Display.getDefault().syncExec( new Runnable() {

      public void run() {
        Shell shell = spoon.getShell();
        GoogleAuthorizationDialog authorizationDialog = new GoogleAuthorizationDialog( shell, getReceiver() );
        authorizationDialog.open( url );
      }
    } );

  } else {
    browse( url );
  }
}
 
Example 2
Source File: CustomAuthorizationCodeInstalledApp.java    From hop with Apache License 2.0 5 votes vote down vote up
protected void onAuthorization( AuthorizationCodeRequestUrl authorizationUrl ) throws IOException {
  String url = authorizationUrl.build();
  HopGui hopGui = HopGui.getInstance();
  if ( hopGui != null ) {

    Display.getDefault().syncExec( () -> {
      Shell shell = hopGui.getShell();
      GoogleAuthorizationDialog authorizationDialog = new GoogleAuthorizationDialog( shell, getReceiver() );
      authorizationDialog.open( url );
    } );

  } else {
    browse( url );
  }
}
 
Example 3
Source File: OAuthAuthenticator.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create authentication URL.
 *
 * @param requestUrl URL of current HTTP request. This parameter required to be able determine URL
 *     for redirection after authentication. If URL contains query parameters they will be copy to
 *     'state' parameter and returned to callback method.
 * @param scopes specify exactly what type of access needed
 * @return URL for authentication
 */
public String getAuthenticateUrl(URL requestUrl, List<String> scopes)
    throws OAuthAuthenticationException {
  if (!isConfigured()) {
    throw new OAuthAuthenticationException(AUTHENTICATOR_IS_NOT_CONFIGURED);
  }

  AuthorizationCodeRequestUrl url =
      flow.newAuthorizationUrl().setRedirectUri(findRedirectUrl(requestUrl)).setScopes(scopes);
  url.setState(prepareState(requestUrl));
  return url.build();
}
 
Example 4
Source File: AuthorizationCodeInstalledApp.java    From google-oauth-java-client with Apache License 2.0 2 votes vote down vote up
/**
 * Handles user authorization by redirecting to the OAuth 2.0 authorization server.
 *
 * <p>
 * Default implementation is to call {@code browse(authorizationUrl.build())}. Subclasses may
 * override to provide optional parameters such as the recommended state parameter. Sample
 * implementation:
 * </p>
 *
 * <pre>
&#64;Override
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException {
  authorizationUrl.setState("xyz");
  super.onAuthorization(authorizationUrl);
}
 * </pre>
 *
 * @param authorizationUrl authorization URL
 * @throws IOException I/O exception
 */
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException {
  String url = authorizationUrl.build();
  Preconditions.checkNotNull(url);
  browser.browse(url);
}