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;
}
Aggregations