public static String getLoginURL(Req req, OAuthProvider provider, String oauthDomain) { if (OAUTH.isEmpty()) { Log.warn("OAuth is not configured!"); } String name = provider.getName().toLowerCase(); Config providerConfig = OAUTH.sub(name); Value<String> clientId = providerConfig.entry("clientId").str(); Value<String> clientSecret = providerConfig.entry("clientSecret").str(); String callbackPath = Msc.specialUri(name + "OauthCallback"); boolean popup = req.param("popup", null) != null; String redirectUrl = U.notEmpty(oauthDomain) ? oauthDomain + callbackPath : HttpUtils.constructUrl(req, callbackPath); String statePrefix = popup ? "P" : "N"; String state = statePrefix + STATE_CHECK.generateState(clientSecret, req.sessionId()); try { OAuthClientRequest request = OAuthClientRequest.authorizationLocation(provider.getAuthEndpoint()) .setClientId(clientId.str().get()).setRedirectURI(redirectUrl).setScope(provider.getEmailScope()) .setState(state).setResponseType("code").buildQueryMessage(); return request.getLocationUri(); } catch (OAuthSystemException e) { throw U.rte(e); } }
.setRedirectURI(callbackUrl) .setResponseType(FacebookAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state) .buildQueryMessage(); response.sendRedirect(authzRequest.getLocationUri());
.setRedirectURI(callbackUrl) .setResponseType(FacebookAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state) .buildQueryMessage(); response.sendRedirect(authzRequest.getLocationUri());
.setClientId(clientId) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(OIDCAuthenticatorConstants.OAUTH_OIDC_SCOPE).setState(state) .buildQueryMessage(); .setClientId(clientId).setRedirectURI(callbackurl) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state).buildQueryMessage();
authzRequest = OAuthClientRequest.authorizationLocation(authorizationEP).setClientId(clientId) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(OIDCAuthenticatorConstants.OAUTH_OIDC_SCOPE).setState(state).buildQueryMessage(); .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE).setScope(scope) .setState(state).buildQueryMessage();
.setRedirectURI(callbackUrl) .setResponseType(FacebookAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state) .buildQueryMessage(); response.sendRedirect(authzRequest.getLocationUri());
public static URL getOAuth2URL(OAuth2Provider provider, String returnUrl) { log.trace("getOAuth2URL {}", provider); String oAuth2Location = provider.getAuthLocation(); String oAuth2ClientId = provider.getClientId(); String scopes = Utils.toCsv(provider.getPermissionScopes(), false); try { String state = toState(provider.getProviderId(), returnUrl); OAuthClientRequest oAuthRequest = OAuthClientRequest .authorizationLocation(oAuth2Location) .setClientId(oAuth2ClientId) .setResponseType("code") .setScope(scopes) .setState(state) .setRedirectURI(provider.getRedirectURI()) .buildQueryMessage(); return new URL(oAuthRequest.getLocationUri()); } catch (OAuthSystemException oAuthSystemException) { throw new RuntimeException(oAuthSystemException); } catch (MalformedURLException malformedURLException) { throw new RuntimeException(malformedURLException); } }
public OAuth(Client client, OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) { this(client, OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes), OAuthClientRequest.authorizationLocation(authorizationUrl).setScope(scopes)); switch (flow) { case accessCode: tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE); authenticationRequestBuilder.setResponseType(OAuth.CODE); break; case implicit: tokenRequestBuilder.setGrantType(GrantType.IMPLICIT); authenticationRequestBuilder.setResponseType(OAuth.TOKEN); break; case password: tokenRequestBuilder.setGrantType(GrantType.PASSWORD); break; case application: tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS); break; default: break; } }
@Override public String buildAuthorizationURL(final String redirectUri) { try { return OAuthClientRequest .authorizationLocation(authorizationEndpointURL) .setClientId(clientId) .setRedirectURI(redirectUri) .setResponseType(ResponseType.CODE.toString()) .setScope(scope) .buildQueryMessage() .getLocationUri(); } catch (OAuthSystemException e) { throw new RuntimeException("Failed to build the authorization uri.", e); } }
public OAuthClientRequest createRequest(){ try { return OAuthClientRequest.authorizationProvider(providerType).setClientId(clientId).setResponseType(OAuth.OAUTH_CODE) .setScope("email"). setRedirectURI(redirectUrl).buildQueryMessage(); } catch (OAuthSystemException e) { throw new RuntimeException(e); } } public String authorize(String code){