From 3eca2d134ce11e636f04419516735baef68b2b0e Mon Sep 17 00:00:00 2001 From: vimukthiRajapaksha Date: Wed, 13 Nov 2024 16:15:57 +0530 Subject: [PATCH 1/2] Add support for rich authorization requests --- .../src/main/webapp/oauth2_authz.jsp | 56 +++++++++++++++- .../src/main/webapp/oauth2_consent.jsp | 67 ++++++++++++++++--- 2 files changed, 114 insertions(+), 9 deletions(-) diff --git a/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_authz.jsp b/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_authz.jsp index a5a86614250..fd104a6a8d7 100644 --- a/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_authz.jsp +++ b/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_authz.jsp @@ -1,6 +1,6 @@ <%-- ~ - ~ Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. + ~ Copyright (c) 2023-2024, WSO2 LLC. (https://www.wso2.com). All Rights Reserved. ~ ~ This software is the property of WSO2 LLC. and its suppliers, if any. ~ Dissemination of any information or reproduction of any material contained @@ -10,6 +10,7 @@ --%> <%@ page import="org.apache.commons.collections.CollectionUtils" %> +<%@ page import="org.apache.commons.collections.MapUtils" %> <%@ page import="org.apache.commons.lang.StringUtils" %> <%@ page import="org.owasp.encoder.Encode" %> <%@ page import="org.wso2.carbon.identity.application.authentication.endpoint.util.Constants" %> @@ -62,6 +63,20 @@ } boolean displayScopes = Boolean.parseBoolean(getServletContext().getInitParameter("displayScopes")); + + final String authorizationDetailsParam = request.getParameter("authorization_details"); + final Map authorizationDetailsToBeDisplayed = new HashMap<>(); + if (StringUtils.isNotBlank(authorizationDetailsParam)) { + final JSONArray authorizationDetails = new JSONArray(authorizationDetailsParam); + for (int index = 0; index < authorizationDetails.length(); index++) { + JSONObject authorizationDetail = authorizationDetails.getJSONObject(index); + + // Check if consent description is not empty, otherwise use type. + final String description = authorizationDetail.optString("_description", authorizationDetail.getString("type")); + final String authorizationDetailId = "authorization_detail_id_" + authorizationDetail.getString("_id"); + authorizationDetailsToBeDisplayed.put(authorizationDetailId, description); + } + } %> <%-- Data for the layout from the page --%> @@ -233,6 +248,45 @@ } %> + <% + if (MapUtils.isNotEmpty(authorizationDetailsToBeDisplayed)) { + %> +
+
+
+ +
+
+ <%=AuthenticationEndpointUtil.i18n(resourceBundle, "requested.authorization-details")%> +
+
+
+
+
+ <% + for (Map.Entry authorizationDetailEntry : authorizationDetailsToBeDisplayed.entrySet()) { + %> +
+
+ + +
+
+ <% + } + %> +
+
+
+
+
+
+ <% + } + %> + - + @@ -392,6 +407,42 @@ } } %> + + <% + if (MapUtils.isNotEmpty(authorizationDetailsToBeDisplayed)) { + %> +
+ +
+
+ <%=AuthenticationEndpointUtil.i18n(resourceBundle, "requested.authorization-details")%> +
+
+
+
+
+ <% + for (Map.Entry authorizationDetailEntry : authorizationDetailsToBeDisplayed.entrySet()) { + %> +
+
+ + +
+
+ <% + } + %> +
+
+
+
+ <% + } + %> + From 230e379a26771a07d050af758c2d32893e152f72 Mon Sep 17 00:00:00 2001 From: vimukthiRajapaksha Date: Wed, 13 Nov 2024 16:21:33 +0530 Subject: [PATCH 2/2] Add rich authorization requests i18n --- .../endpoint/i18n/Resources.properties | 1 + .../src/main/webapp/oauth2_consent.jsp | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/identity-apps-core/apps/authentication-portal/src/main/resources/org/wso2/carbon/identity/application/authentication/endpoint/i18n/Resources.properties b/identity-apps-core/apps/authentication-portal/src/main/resources/org/wso2/carbon/identity/application/authentication/endpoint/i18n/Resources.properties index 48db124d9ba..5b1c3d22a13 100644 --- a/identity-apps-core/apps/authentication-portal/src/main/resources/org/wso2/carbon/identity/application/authentication/endpoint/i18n/Resources.properties +++ b/identity-apps-core/apps/authentication-portal/src/main/resources/org/wso2/carbon/identity/application/authentication/endpoint/i18n/Resources.properties @@ -192,6 +192,7 @@ under.construction=This page is under construction by.selecting.following.attributes=By selecting the following attributes you agree to share them with select.all=Select All requested.scopes=Obtain permission for +requested.authorization-details=Gain consent for requested.attributes=Know some of your details please.select.approve.always=Please select either "Approve Once" or "Approve Always" to provide consent to requested scopes to continue ok=Ok diff --git a/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_consent.jsp b/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_consent.jsp index d3d32bb2460..c6889b1ce57 100644 --- a/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_consent.jsp +++ b/identity-apps-core/apps/authentication-portal/src/main/webapp/oauth2_consent.jsp @@ -58,22 +58,22 @@ JSONArray scopeArray = new JSONArray (jsonObj.get("scopes").toString()); for (int scopeCount = 0; scopeCount < scopeArray.length(); scopeCount++) { JSONObject scope = (JSONObject) scopeArray.get(scopeCount); - + // Get the displayName. String displayName = (String) scope.get("displayName"); - + // Use optString to get description; it returns "" if the key is not found. String description = scope.optString("description", ""); // Check if description is not empty, otherwise use displayName. String scopeName = !StringUtils.isBlank(description) ? description : displayName; - + // Add the determined scopeName to the scopes list. scopes.add(scopeName); - + // Add the identifier to the scopesWithMetadata list scopesWithMetadata.add((String) scope.get("identifier")); - } + } scopeDetails.put(key,scopes); } } @@ -248,7 +248,7 @@ - +