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); } }
private String getAuthorizationCode() { try { AuthenticationRequestBuilder builder = OAuthClientRequest.authorizationLocation(authorizationLocation.toString()) .setClientId(clientID).setRedirectURI(callbackURL.toString()); if (responseType != null) { builder.setResponseType(responseType); } OAuthClientRequest request = builder.buildQueryMessage(); // FIXME : remove those Syso when the studio activate the INFO log by default System.out.println(messages.getMessage("msg.info.showAuthorizUrl")); System.out.println(request.getLocationUri()); // -- logger.info(messages.getMessage("msg.info.showAuthorizUrl")); logger.info(request.getLocationUri()); OAuth2ImplicitGrantServer service = new OAuth2ImplicitGrantServer(callbackURL.getHost(), callbackURL.getPort(), 10 * 60 * 1000); service.run();// <--- this method wait for 10 minutes maximum to grab authorization code String code = service.getAuthorizationCode(); service.stop(); return code; } catch (Exception e) { throw new RuntimeException(e); } }
.setResponseType(FacebookAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state) .buildQueryMessage(); response.sendRedirect(authzRequest.getLocationUri()); } catch (IOException e) {
.setClientId(clientId) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setState(state).buildQueryMessage(); } else if (queryString != null && queryString.toLowerCase().contains("scope=")) { authzRequest = OAuthClientRequest.authorizationLocation(authorizationEP) .setClientId(clientId).setRedirectURI(callbackurl) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setState(state).buildQueryMessage(); } else if (queryString != null && queryString.toLowerCase().contains("redirect_uri=")) { .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).setState(state) .buildQueryMessage(); } else if (StringUtils.isNotBlank(queryString) && queryString.toLowerCase().contains("scope=")) { authzRequest = OAuthClientRequest.authorizationLocation(authorizationEP).setClientId(clientId) .setRedirectURI(callbackurl) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE).setState(state) .buildQueryMessage(); } else if (StringUtils.isNotBlank(queryString) && queryString.toLowerCase().contains("redirect_uri=")) { authzRequest = OAuthClientRequest.authorizationLocation(authorizationEP).setClientId(clientId) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(OIDCAuthenticatorConstants.OAUTH_OIDC_SCOPE).setState(state).buildQueryMessage(); .setRedirectURI(callbackurl) .setResponseType(OIDCAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE).setScope(scope) .setState(state).buildQueryMessage();
.setResponseType(FacebookAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state) .buildQueryMessage(); response.sendRedirect(authzRequest.getLocationUri()); } catch (IOException e) {
.setResponseType(FacebookAuthenticatorConstants.OAUTH2_GRANT_TYPE_CODE) .setScope(scope).setState(state) .buildQueryMessage(); response.sendRedirect(authzRequest.getLocationUri()); } catch (IOException e) {
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 String getAuthorizationUri() throws OAuthSystemException { return getAuthorizationEndPoint().buildQueryMessage().getLocationUri(); }
@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){
public String generateForwardUrl(String registrationEndpoint, String authorizeUrl, String returnUrl) throws ServerException, UserException { try (DatabaseSession session = getBimServer().getDatabase().createSession()) { OAuthServer oAuthServer = session.querySingle(StorePackage.eINSTANCE.getOAuthServer_RegistrationEndpoint(), registrationEndpoint); if (oAuthServer == null) { throw new UserException("Application not registered"); } OAuthClientRequest request2 = OAuthClientRequest.authorizationLocation(authorizeUrl).setParameter("auth_type", "service").setClientId(oAuthServer.getClientId()).setRedirectURI(returnUrl).setResponseType(ResponseType.CODE.toString()).setState("state").buildQueryMessage(); return request2.getLocationUri(); } catch (Exception e) { return handleException(e); } }