Search in sources :

Example 6 with TokenBinder

use of org.wso2.carbon.identity.oauth2.token.bindings.TokenBinder in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpoint method handleSuccessAuthorization.

private OAuthResponse handleSuccessAuthorization(OAuthMessage oAuthMessage, OIDCSessionState sessionState, OAuth2Parameters oauth2Params, String responseType, OAuth2AuthorizeRespDTO authzRespDTO) throws OAuthSystemException {
    OAuthASResponse.OAuthAuthorizationResponseBuilder builder = OAuthASResponse.authorizationResponse(oAuthMessage.getRequest(), HttpServletResponse.SC_FOUND);
    // all went okay
    if (isAuthorizationCodeExists(authzRespDTO)) {
        // Get token binder if it is enabled for the client.
        Optional<TokenBinder> tokenBinderOptional = getTokenBinder(oauth2Params.getClientId());
        String tokenBindingValue = null;
        if (tokenBinderOptional.isPresent()) {
            TokenBinder tokenBinder = tokenBinderOptional.get();
            tokenBindingValue = tokenBinder.getOrGenerateTokenBindingValue(oAuthMessage.getRequest());
            tokenBinder.setTokenBindingValueForResponse(oAuthMessage.getResponse(), tokenBindingValue);
            if (LoggerUtils.isDiagnosticLogsEnabled()) {
                Map<String, Object> params = new HashMap<>();
                params.put("clientId", oauth2Params.getClientId());
                params.put("tokenBindingValue", tokenBindingValue);
                Map<String, Object> configs = new HashMap<>();
                configs.put("tokenBinderType", tokenBinder.getBindingType());
                LoggerUtils.triggerDiagnosticLogEvent(OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, params, OAuthConstants.LogConstants.SUCCESS, "Successfully generated token binding value.", "generate-token-binding-value", configs);
            }
        }
        setAuthorizationCode(oAuthMessage, authzRespDTO, builder, tokenBindingValue);
    }
    if (isResponseTypeNotIdTokenOrNone(responseType, authzRespDTO)) {
        setAccessToken(authzRespDTO, builder);
        setScopes(authzRespDTO, builder);
    }
    if (isIdTokenExists(authzRespDTO)) {
        setIdToken(authzRespDTO, builder);
        oAuthMessage.setProperty(OIDC_SESSION_ID, authzRespDTO.getOidcSessionId());
    }
    if (StringUtils.isNotBlank(oauth2Params.getState())) {
        builder.setParam(OAuth.OAUTH_STATE, oauth2Params.getState());
    }
    String redirectURL = authzRespDTO.getCallbackURI();
    OAuthResponse oauthResponse;
    if (RESPONSE_MODE_FORM_POST.equals(oauth2Params.getResponseMode())) {
        oauthResponse = handleFormPostMode(oAuthMessage, builder, redirectURL);
    } else {
        oauthResponse = builder.location(redirectURL).buildQueryMessage();
    }
    if (LoggerUtils.isDiagnosticLogsEnabled()) {
        Map<String, Object> params = new HashMap<>();
        params.put("clientId", oauth2Params.getClientId());
        params.put("responseMode", oauth2Params.getResponseMode());
        params.put("redirectUrl", redirectURL);
        LoggerUtils.triggerDiagnosticLogEvent(OAuthConstants.LogConstants.OAUTH_INBOUND_SERVICE, params, OAuthConstants.LogConstants.SUCCESS, "Successfully generated oauth response.", "generate-response", null);
    }
    sessionState.setAuthenticated(true);
    return oauthResponse;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RequestObject(org.wso2.carbon.identity.openidconnect.model.RequestObject) JSONObject(org.json.JSONObject) OAuthASResponse(org.apache.oltu.oauth2.as.response.OAuthASResponse) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse) TokenBinder(org.wso2.carbon.identity.oauth2.token.bindings.TokenBinder)

Aggregations

TokenBinder (org.wso2.carbon.identity.oauth2.token.bindings.TokenBinder)6 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)5 InvalidOAuthClientException (org.wso2.carbon.identity.oauth.common.exception.InvalidOAuthClientException)3 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 OAuthASResponse (org.apache.oltu.oauth2.as.response.OAuthASResponse)2 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)2 JSONObject (org.json.JSONObject)2 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)2 SignedJWT (com.nimbusds.jwt.SignedJWT)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLEncoder (java.net.URLEncoder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 ParseException (java.text.ParseException)1