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 ); } } }
/** * Handles user authorization by redirecting to the OAuth 2.0 authorization server. * * <p> * Default implementation is to call {@code resp.sendRedirect(authorizationUrl.build())}. * Subclasses may override to provide optional parameters such as the recommended state parameter. * Sample implementation: * </p> * * <pre> @Override protected void onAuthorization(HttpServletRequest req, HttpServletResponse resp, AuthorizationCodeRequestUrl authorizationUrl) throws ServletException, IOException { authorizationUrl.setState("xyz"); super.onAuthorization(req, resp, authorizationUrl); } * </pre> * * @param authorizationUrl authorization code request URL * @param req HTTP servlet request * @throws ServletException servlet exception * @since 1.11 */ protected void onAuthorization(HttpServletRequest req, HttpServletResponse resp, AuthorizationCodeRequestUrl authorizationUrl) throws ServletException, IOException { resp.sendRedirect(authorizationUrl.build()); } }
public void authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { List <String> scopes = new LinkedList<String>(); scopes.add(scope); AuthorizationCodeRequestUrl authorize = new GoogleAuthorizationCodeRequestUrl(client_id, redirect_uri, scopes); authorize.setRedirectUri(redirect_uri); String authorize_url = authorize.build(); log.info(authorize_url); response.sendRedirect(authorize_url); }
@Override protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException { try { Desktop.isDesktopSupported(); browse(authorizationUrl.build()); } catch (Exception e) { LOG.warn("Failed to open browser with Desktop browse method."); browseWithProgramLauncher(authorizationUrl.build()); } } }
@Override protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws IOException { try { Desktop.isDesktopSupported(); browse(authorizationUrl.build()); } catch (Exception e) { LOG.warn("Failed to open browser with Desktop browse method."); browseWithProgramLauncher(authorizationUrl.build()); } } }
@RequestMapping(value="/authenticate.do" , method={ RequestMethod.GET , RequestMethod.POST }) public void authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { List <String> scopes = new LinkedList<String>(); scopes.add(scope); AuthorizationCodeRequestUrl authorize = new GoogleAuthorizationCodeRequestUrl(client_id, redirect_uri, scopes); authorize.setRedirectUri(redirect_uri); String authorize_url = authorize.build(); log.info(authorize_url); response.sendRedirect(authorize_url); }
protected void onAuthorization(AuthorizationCodeRequestUrl authorizationUrl) throws java.io.IOException { Gdx.net.openURI(authorizationUrl.build()); } }.authorize(userID);
/** * Gets the authorization URL to retrieve the authorization code. */ @Nullable public String getAuthorizationUrl() throws UnsupportedEncodingException { String authorizationCodeRequestUrl = authorizationCodeFlow.newAuthorizationUrl().setScopes(scopes).build(); if (redirectUri != null) { authorizationCodeRequestUrl += "&redirect_uri=" + URLEncoder.encode(redirectUri, "UTF-8"); } return authorizationCodeRequestUrl; }
@Override public String getRedirectedUrl() { String uuid = UUID.randomUUID().toString(); log.trace("Registered oauth state {}", uuid); cache.put(uuid, DUMMY); return codeFlow.newAuthorizationUrl() .setState(uuid) .setRedirectUri(configuration.getRedirectedUri()).build(); }
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); } }
/** * 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> @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); }
/** * 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; }
/** * Returns the authorization endpoint URI for this object. * @param redirectionEndpoint redirection endpoint URI for the * authorization request; if this argument is <code>null</code>, the * <code>redirect_uri</code> parameter shall not be used. * @param state opaque state string for the authorization request; if this * argument is <code>null</code>, the <code>state</code> parameter shall * not be used * @return authorization endpoint URI * @throws URISyntaxException if the authorization endpoint URI could not * be constructed * @throws NullPointerException if this object has no client credentials */ public URI getAuthorizationEndpoint(URI redirectionEndpoint, String state) throws URISyntaxException { AuthorizationCodeFlow flow = getAuthorizationCodeFlow(false); AuthorizationCodeRequestUrl request = flow.newAuthorizationUrl(); if (redirectionEndpoint != null) { request.setRedirectUri(redirectionEndpoint.toString()); } if (state != null) { request.setState(state); } return new URI(request.build()); }
@Override public String getAuthorizationUrl(HttpServletRequest request) { return getAuthorizationCodeFlow().newAuthorizationUrl().setRedirectUri(getCallbackUrl(request)).build(); }
@Override public String getAuthorizationUrl(String serverURL) { return getAuthorizationCodeFlow().newAuthorizationUrl().setRedirectUri(getCallbackUrl(serverURL)).build(); }
/** * 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(); }
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); } }
private String authorize(String redirectUri) { AuthorizationCodeRequestUrl authorizationUrl; Details web = new Details(); GoogleCalendarSettings googleCalendarSettings = settingsService.getSettings().getCalendarSettings().getGoogleCalendarSettings(); web.setClientId(googleCalendarSettings.getClientId()); web.setClientSecret(googleCalendarSettings.getClientSecret()); GoogleClientSecrets clientSecrets = new GoogleClientSecrets(); clientSecrets.setWeb(web); flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)) .setApprovalPrompt("force") .setAccessType("offline") .build(); authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectUri); LOG.info("using authorizationUrl " + authorizationUrl); return authorizationUrl.build(); } }
.setScopes(OAuthScopeRegistry.getScopes()); BrowserUtil.browse(authCodeRequestUrl.build());