Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tenant domain to jwt payload #2384

Merged
merged 5 commits into from
Mar 12, 2024

Conversation

chamilaadhi
Copy link
Contributor

@chamilaadhi chamilaadhi commented Feb 27, 2024

Proposed changes in this pull request

When SP is created with saas app enabled, it is not possible to identify the tenant domain of the user. Also, it is not possible to identify the SP's tenant domain as well. For that had a chat with @janakamarasena and decided to introduce two new custom fields to the JWT token (user_domain and app_domain). It was decided to introduce a flag to enable this to the jwt.

This will be enabled only if the following config is added

[oauth]
add_tenant_domain_to_access_token = true

PR related to the config wso2/carbon-identity-framework#5547

@@ -641,6 +645,11 @@ public String getDeviceAuthzEPUrl() {

return deviceAuthzEPUrl;
}

public boolean isAddTenantDomainToTokenEnabled() {
return addTenantDomainToTokenEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line after the method definition. Check other places as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with 5ec7232

@@ -3348,6 +3369,8 @@ private class ConfigElements {
private static final String OPENID_CONNECT_ADD_TENANT_DOMAIN_TO_ID_TOKEN = "AddTenantDomainToIdToken";
// Property to decide whether to add userstore domain to id_token.
private static final String OPENID_CONNECT_ADD_USERSTORE_DOMAIN_TO_ID_TOKEN = "AddUserstoreDomainToIdToken";
// Enable/Disable adding domain information to the token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Enable/Disable adding domain information to the token
// Enable/Disable adding domain information to the token.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 105 to 106
private static final String APP_DOMAIN = "app_domain";
private static final String USER_DOMAIN = "user_domain";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we have the word tenant domain in the claim. specially when using user_domain this could be confused with userstore domian.
some suggetions,
app_domain -> app_td
user_domain -> user_td

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed as suggested

@@ -3348,6 +3370,8 @@ private class ConfigElements {
private static final String OPENID_CONNECT_ADD_TENANT_DOMAIN_TO_ID_TOKEN = "AddTenantDomainToIdToken";
// Property to decide whether to add userstore domain to id_token.
private static final String OPENID_CONNECT_ADD_USERSTORE_DOMAIN_TO_ID_TOKEN = "AddUserstoreDomainToIdToken";
// Enable/Disable adding domain information to the token.
private static final String ADD_DOMAIN_TO_ACCESS_TOKEN = "AddTenantDomainToAccessToken";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final String ADD_DOMAIN_TO_ACCESS_TOKEN = "AddTenantDomainToAccessToken";
private static final String ADD_TENANT_DOMAIN_TO_ACCESS_TOKEN = "AddTenantDomainToAccessToken";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment on lines 105 to 106
private static final String APP_DOMAIN = "app_td";
private static final String USER_DOMAIN = "user_td";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static final String APP_DOMAIN = "app_td";
private static final String USER_DOMAIN = "user_td";
private static final String APP_TENANT_DOMAIN = "app_td";
private static final String USER_TENANT_DOMAIN = "user_td";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -479,6 +481,11 @@ protected JWTClaimsSet createJWTClaimSet(OAuthAuthzReqMessageContext authAuthzRe
jwtClaimsSetBuilder.notBeforeTime(new Date(curTimeInMillis));
jwtClaimsSetBuilder.claim(CLIENT_ID, consumerKey);

if (OAuthServerConfiguration.getInstance().isAddTenantDomainToAccessTokenEnabled()) {
jwtClaimsSetBuilder.claim(APP_DOMAIN, oAuthAppDO.getAppOwner().getTenantDomain());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oAuthAppDO.getAppOwner().getTenantDomain() this seems to be resolving the tenant domain of the app through the appowners tenant domain. lets directly resolve the apps tenant domain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HiranyaKavishani HiranyaKavishani merged commit ebb0d7e into wso2-extensions:6.13.x Mar 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants