/** * 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(); }
/** * Starts the login session. */ @SuppressFBWarnings("J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION") public HttpResponse doCommenceLogin() throws IOException { // remember this in the session Stapler.getCurrentRequest().getSession().setAttribute(SESSION_NAME, this); AuthorizationCodeRequestUrl authorizationCodeRequestUrl = flow.newAuthorizationUrl().setState(uuid).setRedirectUri(redirectUrl); return new HttpRedirect(authorizationCodeRequestUrl.toString()); }
/** * 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(); }
flow.newAuthorizationUrl().setRedirectUri(WebUtil.buildUrl(req, "/oauth2callback")); url.set("approval_prompt", "force"); res.sendRedirect(url.build());
AuthorizationCodeRequestUrl authorizationUrl = flow.newAuthorizationUrl(); authorizationUrl.setRedirectUri(getRedirectUri(req)); onAuthorization(req, resp, authorizationUrl);
/** * 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(); }
.setScopes(scopes) .build(); final AuthorizationCodeRequestUrl authorizationCodeRequestUrl = flow.newAuthorizationUrl(); authorizationCodeRequestUrl.setRedirectUri(redirectUri); authorizationCodeRequestUrl.setState(new AlphanumericRandomStringService().random());
/** * Authorizes the installed application to access user's protected data. * * @param userId user ID or {@code null} if not using a persisted credential store * @return credential */ public Credential authorize(String userId) throws IOException { try { Credential credential = flow.loadCredential(userId); if (credential != null && (credential.getRefreshToken() != null || credential.getExpiresInSeconds() == null || credential.getExpiresInSeconds() > 60)) { return credential; } // open in browser String redirectUri = receiver.getRedirectUri(); AuthorizationCodeRequestUrl authorizationUrl = flow.newAuthorizationUrl().setRedirectUri(redirectUri); onAuthorization(authorizationUrl); // receive authorization code and exchange it for an access token String code = receiver.waitForCode(); TokenResponse response = flow.newTokenRequest(code).setRedirectUri(redirectUri).execute(); // store credential and return it return flow.createAndStoreCredential(response, userId); } finally { receiver.stop(); } }