org.apache.oltu.oauth2.common.message.types.GrantType Java Examples

The following examples show how to use org.apache.oltu.oauth2.common.message.types.GrantType. 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: RetryingOAuth.java    From eve-esi with Apache License 2.0 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch (flow) {
    case accessCode:
        tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
        break;
    case implicit:
        tokenRequestBuilder.setGrantType(GrantType.IMPLICIT);
        break;
    case password:
        tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
        break;
    case application:
        tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
        break;
    default:
        break;
    }
}
 
Example #2
Source File: OAuth.java    From docusign-java-client with MIT License 6 votes vote down vote up
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;
	}
}
 
Example #3
Source File: AbstractAuthorizationGrantHandler.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean validateScope(OAuthTokenReqMessageContext tokReqMsgCtx)
        throws IdentityOAuth2Exception {
    OAuthCallback scopeValidationCallback = new OAuthCallback(tokReqMsgCtx.getAuthorizedUser(),
            tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId(), OAuthCallback.OAuthCallbackType
            .SCOPE_VALIDATION_TOKEN);
    scopeValidationCallback.setRequestedScope(tokReqMsgCtx.getScope());
    if (tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType().equals(
            org.wso2.carbon.identity.oauth.common.GrantType.SAML20_BEARER.toString())) {
        scopeValidationCallback.setCarbonGrantType(org.wso2.carbon.identity.oauth.common.GrantType.valueOf(
                OAuthConstants.OAUTH_SAML2_BEARER_GRANT_ENUM.toString()));
    } else if (tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType().equals(
            org.wso2.carbon.identity.oauth.common.GrantType.IWA_NTLM.toString())) {
        scopeValidationCallback.setCarbonGrantType(org.wso2.carbon.identity.oauth.common.GrantType.valueOf(
                OAuthConstants.OAUTH_IWA_NTLM_GRANT_ENUM.toString()));
    } else {
        scopeValidationCallback.setGrantType(tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType());
    }

    callbackManager.handleCallback(scopeValidationCallback);
    tokReqMsgCtx.setValidityPeriod(scopeValidationCallback.getValidityPeriod());
    tokReqMsgCtx.setScope(scopeValidationCallback.getApprovedScope());
    return scopeValidationCallback.isValidScope();
}
 
Example #4
Source File: AbstractAuthorizationGrantHandler.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public boolean authorizeAccessDelegation(OAuthTokenReqMessageContext tokReqMsgCtx)
        throws IdentityOAuth2Exception {
    OAuthCallback authzCallback = new OAuthCallback(tokReqMsgCtx.getAuthorizedUser(),
            tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId(),
            OAuthCallback.OAuthCallbackType.ACCESS_DELEGATION_TOKEN);
    authzCallback.setRequestedScope(tokReqMsgCtx.getScope());
    if (tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType().equals(
            org.wso2.carbon.identity.oauth.common.GrantType.SAML20_BEARER.toString())) {
        authzCallback.setCarbonGrantType(org.wso2.carbon.identity.oauth.common.GrantType.valueOf(
                OAuthConstants.OAUTH_SAML2_BEARER_GRANT_ENUM.toString()));
    } else if (tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType().equals(
            org.wso2.carbon.identity.oauth.common.GrantType.IWA_NTLM.toString())) {
        authzCallback.setCarbonGrantType(org.wso2.carbon.identity.oauth.common.GrantType.valueOf(
                OAuthConstants.OAUTH_IWA_NTLM_GRANT_ENUM.toString()));
    } else {
        authzCallback.setGrantType(tokReqMsgCtx.getOauth2AccessTokenReqDTO().getGrantType());
    }
    callbackManager.handleCallback(authzCallback);
    tokReqMsgCtx.setValidityPeriod(authzCallback.getValidityPeriod());
    return authzCallback.isAuthorized();
}
 
Example #5
Source File: OpenIDConnectAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private OAuthClientRequest getAccessRequest(String tokenEndPoint, String clientId, String code, String clientSecret,
                                            String callbackurl)
        throws AuthenticationFailedException {

    OAuthClientRequest accessRequest = null;
    try {
        accessRequest = OAuthClientRequest.tokenLocation(tokenEndPoint)
                .setGrantType(GrantType.AUTHORIZATION_CODE).setClientId(clientId)
                .setClientSecret(clientSecret).setRedirectURI(callbackurl).setCode(code)
                .buildBodyMessage();

    } catch (OAuthSystemException e) {
        if (log.isDebugEnabled()) {
            log.debug("Exception while building request for request access token", e);
        }
        throw new AuthenticationFailedException(e.getMessage(), e);
    }
    return accessRequest;
}
 
Example #6
Source File: OAuth.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public OAuth(Client client, OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) {
    this(client, OAuthClientRequest.tokenLocation(tokenUrl).setScope(scopes));

    switch(flow) {
    case accessCode:
    case implicit:
        tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
        break;
    case password:
        tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
        break;
    case application:
        tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
        break;
    default:
        break;
    }
    authenticationRequestBuilder = OAuthClientRequest.authorizationLocation(authorizationUrl);
}
 
Example #7
Source File: OAuth.java    From android with MIT License 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch(flow) {
    case accessCode:
    case implicit:
        tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
        break;
    case password:
        tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
        break;
    case application:
        tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
        break;
    default:
        break;
    }            
}
 
Example #8
Source File: OAuth.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch(flow) {
    case accessCode:
    case implicit:
        tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
        break;
    case password:
        tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
        break;
    case application:
        tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
        break;
    default:
        break;
    }            
}
 
Example #9
Source File: RetryingOAuth.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch(flow) {
        case accessCode:
            tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
            break;
        case implicit:
            tokenRequestBuilder.setGrantType(GrantType.IMPLICIT);
            break;
        case password:
            tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
            break;
        case application:
            tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
            break;
        default:
            break;
    }
}
 
Example #10
Source File: OAuth.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch(flow) {
    case accessCode:
    case implicit:
        tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
        break;
    case password:
        tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
        break;
    case application:
        tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
        break;
    default:
        break;
    }            
}
 
Example #11
Source File: RetryingOAuth.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch(flow) {
        case accessCode:
            tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
            break;
        case implicit:
            tokenRequestBuilder.setGrantType(GrantType.IMPLICIT);
            break;
        case password:
            tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
            break;
        case application:
            tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
            break;
        default:
            break;
    }
}
 
Example #12
Source File: OAuth.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public void setFlow(OAuthFlow flow) {
    switch(flow) {
    case accessCode:
    case implicit:
        tokenRequestBuilder.setGrantType(GrantType.AUTHORIZATION_CODE);
        break;
    case password:
        tokenRequestBuilder.setGrantType(GrantType.PASSWORD);
        break;
    case application:
        tokenRequestBuilder.setGrantType(GrantType.CLIENT_CREDENTIALS);
        break;
    default:
        break;
    }            
}
 
Example #13
Source File: OAuth2TokenEndpoint.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private OAuth2AccessTokenRespDTO getAccessToken(CarbonOAuthTokenRequest oauthRequest) {

        OAuth2AccessTokenReqDTO tokenReqDTO = new OAuth2AccessTokenReqDTO();
        String grantType = oauthRequest.getGrantType();
        tokenReqDTO.setGrantType(grantType);
        tokenReqDTO.setClientId(oauthRequest.getClientId());
        tokenReqDTO.setClientSecret(oauthRequest.getClientSecret());
        tokenReqDTO.setCallbackURI(oauthRequest.getRedirectURI());
        tokenReqDTO.setScope(oauthRequest.getScopes().toArray(new String[oauthRequest.getScopes().size()]));
        tokenReqDTO.setTenantDomain(oauthRequest.getTenantDomain());

        // Check the grant type and set the corresponding parameters
        if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType)) {
            tokenReqDTO.setAuthorizationCode(oauthRequest.getCode());
        } else if (GrantType.PASSWORD.toString().equals(grantType)) {
            tokenReqDTO.setResourceOwnerUsername(oauthRequest.getUsername());
            tokenReqDTO.setResourceOwnerPassword(oauthRequest.getPassword());
        } else if (GrantType.REFRESH_TOKEN.toString().equals(grantType)) {
            tokenReqDTO.setRefreshToken(oauthRequest.getRefreshToken());
        } else if (org.wso2.carbon.identity.oauth.common.GrantType.SAML20_BEARER.toString().equals(grantType)) {
            tokenReqDTO.setAssertion(oauthRequest.getAssertion());
        } else if (org.wso2.carbon.identity.oauth.common.GrantType.IWA_NTLM.toString().equals(grantType)) {
            tokenReqDTO.setWindowsToken(oauthRequest.getWindowsToken());
        } else {
            // Set all request parameters to the OAuth2AccessTokenReqDTO
            tokenReqDTO.setRequestParameters(oauthRequest.getRequestParameters());
        }

        return EndpointUtil.getOAuth2Service().issueAccessToken(tokenReqDTO);
    }
 
Example #14
Source File: OidcHelper.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
public OAuthClientRequest buildOauthRequest(HttpServletRequest request, String code) throws OAuthSystemException {
    return OAuthClientRequest
            .tokenLocation(this.oidcConfiguration.getOidcTokenLocation())
            //.tokenProvider(OAuthProviderType.MICROSOFT)
            .setGrantType(GrantType.AUTHORIZATION_CODE)
            .setClientId(this.oidcConfiguration.getOidcClientId())
            //.setClientSecret("your-facebook-application-client-secret")
            .setRedirectURI(buildRedirectURI(request))
            .setCode(code)
            .setParameter("response_mode", "form_post")
            .buildBodyMessage();

}
 
Example #15
Source File: OAuthClientRequest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public TokenRequestBuilder setGrantType(GrantType grantType) {
    this.parameters.put(OAuth.OAUTH_GRANT_TYPE, grantType == null ? null : grantType.toString());
    return this;
}
 
Example #16
Source File: GitHubOAuthParams.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public GrantType getGrantType() {
	return GRANT_TYPE;
}
 
Example #17
Source File: GoogleOAuthParams.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public GrantType getGrantType() {
	return GRANT_TYPE;
}
 
Example #18
Source File: Oauth2ImplicitClient.java    From components with Apache License 2.0 4 votes vote down vote up
@Override
protected GrantType getGrantType() {
    return GrantType.AUTHORIZATION_CODE;
}
 
Example #19
Source File: Oauth2ImplicitClient.java    From components with Apache License 2.0 4 votes vote down vote up
@Override
protected GrantType getGrantType() {
    return GrantType.REFRESH_TOKEN;
}
 
Example #20
Source File: OAuthTokenHandler.java    From rapidoid with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(Req req) throws Exception {
	String code = req.param("code");
	String state = req.param("state");

	Log.debug("Received OAuth code", "code", code, "state", state);

	if (code != null && !U.isEmpty(state)) {

		String id = clientId.str().get();
		String secret = clientSecret.str().get();

		char statePrefix = state.charAt(0);
		U.must(statePrefix == 'P' || statePrefix == 'N', "Invalid OAuth state prefix!");
		state = state.substring(1);

		U.must(stateCheck.isValidState(state, secret, req.sessionId()), "Invalid OAuth state!");

		boolean popup = statePrefix == 'P';
		Log.debug("OAuth validated", "popup", popup);

		String domain = oauthDomain.getOrNull();
		String redirectUrl = U.notEmpty(domain) ? domain + callbackPath : HttpUtils.constructUrl(req, callbackPath);

		TokenRequestBuilder reqBuilder = OAuthClientRequest.tokenLocation(provider.getTokenEndpoint())
			.setGrantType(GrantType.AUTHORIZATION_CODE)
			.setClientId(id)
			.setClientSecret(secret)
			.setRedirectURI(redirectUrl)
			.setCode(code);

		OAuthClientRequest request = paramsInBody() ? reqBuilder.buildBodyMessage() : reqBuilder.buildBodyMessage();

		OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

		String accessToken = token(request, oAuthClient);

		String profileUrl = Msc.fillIn(provider.getProfileEndpoint(), "token", accessToken);

		OAuthClientRequest bearerClientRequest = new OAuthBearerClientRequest(profileUrl).setAccessToken(
			accessToken).buildQueryMessage();

		OAuthResourceResponse res = oAuthClient.resource(bearerClientRequest,
			org.apache.oltu.oauth2.common.OAuth.HttpMethod.GET, OAuthResourceResponse.class);

		U.must(res.getResponseCode() == 200, "OAuth response error!");

		Map<String, Object> auth = JSON.parseMap(res.getBody());

		String email = (String) U.or(auth.get("email"), auth.get("emailAddress"));
		String firstName = (String) U.or(auth.get("firstName"), U.or(auth.get("first_name"), auth.get("given_name")));
		String lastName = (String) U.or(auth.get("lastName"), U.or(auth.get("last_name"), auth.get("family_name")));
		String name = U.or((String) auth.get("name"), firstName + " " + lastName);

		String username = email;
		Set<String> roles = customization.rolesProvider().getRolesForUser(req, username);

		UserInfo user = new UserInfo(username, roles);
		user.name = name;
		user.email = email;
		user.oauthProvider = provider.getName();
		user.oauthId = String.valueOf(auth.get("id"));

		req.response().authorize(user);

		return req.response().redirect("/");

	} else {
		String error = req.param("error");
		if (error != null) {
			Log.warn("OAuth error", "error", error);
			throw U.rte("OAuth error!");
		}
	}

	throw U.rte("Invalid OAuth request!");
}
 
Example #21
Source File: OAuthParams.java    From orion.server with Eclipse Public License 1.0 votes vote down vote up
public abstract GrantType getGrantType(); 
Example #22
Source File: Oauth2ImplicitClient.java    From components with Apache License 2.0 votes vote down vote up
protected abstract GrantType getGrantType();