From 0f12d1dd0991c52ecc734fba48f9ed7a08a55ac4 Mon Sep 17 00:00:00 2001 From: Reuven Zabirov Date: Thu, 14 Nov 2024 15:34:19 +0200 Subject: [PATCH 1/3] fix sso settings in readme --- README.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9e1651d4..b83f7e66 100644 --- a/README.md +++ b/README.md @@ -890,38 +890,81 @@ You can manage SSO settings and map SSO group roles and user attributes. SsoService ss = descopeClient.getManagementServices().getSsoService(); // You can get SSO settings for a specific tenant ID try { - SSOSettingsResponse resp = ss.getSettings("tenant-id"); + SSOSettingsResponse resp = ss.loadSettings("tenant-id"); } catch (DescopeException de) { // Handle the error } -// You can configure SSO settings manually by setting the required fields directly +// Configure SSO - SAML String tenantId = "tenant-id"; // Which tenant this configuration is for String idpUrl = "https://idp.com"; String entityId = "my-idp-entity-id"; String idpCert = ""; +String idpMetadataUrl = "https://idp.com/metadata"; String redirectUrl = "https://my-app.com/handle-saml"; // Global redirect URL for SSO/SAML List domains = Arrays.asList("domain.com"); // Users logging in from this domain will be logged in to this tenant +// Map IDP groups to Descope roles, or map user attributes. +// This function overrides any previous mapping (even when empty). Use carefully. +List rm = Arrays.asList(new RoleMapping(Arrays.asList("Groups"), "Tenant Role")); +AttributeMapping am = new AttributeMapping("Tenant Name", "Tenant Email", "Tenant Phone Num", "Tenant Group"); + + +// Using Manual Configuration +SSOSAMLSettings manualSettings = new SSOSAMLSettings(idpUrl, entityId, idpCert, am, rm); + try { - ss.configureSettings(tenantId, idpUrl, idpCert, entityId, redirectUrl, domains); + ss.configureSAMLSettings(tenantId, manualSettings, domains); } catch (DescopeException de) { // Handle the error } -// Alternatively, configure using an SSO metadata URL +// Using metadata URL +SSOSAMLSettingsByMetadata metadataSettings = new SSOSAMLSettingsByMetadata(idpMetadataUrl ,am, rm); + try { - ss.configureMetadata(tenantId, "https://idp.com/my-idp-metadata"); + ss.configureSAMLSettingsByMetadata(tenantId, metadataSettings, domains); } catch (DescopeException de) { // Handle the error } -// Map IDP groups to Descope roles, or map user attributes. -// This function overrides any previous mapping (even when empty). Use carefully. -List rm = Arrays.asList(new RoleMapping(Arrays.asList("Groups"), "Tenant Role")); -AttributeMapping am = new AttributeMapping("Tenant Name", "Tenant Email", "Tenant Phone Num", "Tenant Group"); + +public class SSOOIDCSettings { + private String name; + private String clientId; + private String clientSecret; + private String redirectUrl; + private String authUrl; + private String tokenUrl; + private String userDataUrl; + private List scope; + @JsonProperty("JWKsUrl") + private String jwksUrl; + private OIDCAttributeMapping userAttrMapping; + private Boolean manageProviderTokens; + private String callbackDomain; + private List prompt; + private String grantType; + private String issuer; +} + +// Configure SSO - OIDC +String name = "Provider"; // Name of the provider +String clientId = ""; // The client id set on the IdP +String clientSecret = ""; // The client secret on the IdP +String redirectUrl = "https://my-app.com/redirect"; // Optional - a custom redirect url +String authUrl = "https://idp.com/auth"; // The IdP's authentication endpoint +String tokenUrl = "https://idp.com/token"; // The IdP's token endpoint +String userDataUrl = "https://idp.com/user"; // The IdP's user endpoint +List scope = Arrays.asList("openid", "profile"); // The scopes +String grantType = "implicit"; // The grant type +List domains = Arrays.asList("domain.com"); // Users logging in from this domain will be logged in to this tenant + + +SSOOIDCSettings oidcSettings = new SSOOIDCSettings(name, clientId, clientSecret, redirectUrl, authUrl, tokenUrl, userDataUrl, scope, grantType); + try { - ss.configureMapping(tenantId, rm, am); + ss.configureSAMLSettingsByMetadata(tenantId, oidcSettings, domains); } catch (DescopeException de) { // Handle the error } From 1de64db4e7cafcca170b3417790bdc72d0ce4cb0 Mon Sep 17 00:00:00 2001 From: Reuven Zabirov Date: Thu, 14 Nov 2024 15:36:19 +0200 Subject: [PATCH 2/3] remove changes --- README.md | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/README.md b/README.md index b83f7e66..0641016a 100644 --- a/README.md +++ b/README.md @@ -928,26 +928,6 @@ try { // Handle the error } - -public class SSOOIDCSettings { - private String name; - private String clientId; - private String clientSecret; - private String redirectUrl; - private String authUrl; - private String tokenUrl; - private String userDataUrl; - private List scope; - @JsonProperty("JWKsUrl") - private String jwksUrl; - private OIDCAttributeMapping userAttrMapping; - private Boolean manageProviderTokens; - private String callbackDomain; - private List prompt; - private String grantType; - private String issuer; -} - // Configure SSO - OIDC String name = "Provider"; // Name of the provider String clientId = ""; // The client id set on the IdP From cb2e353607394f3c3cbea8ea87914f80a5c358d6 Mon Sep 17 00:00:00 2001 From: Reuven Zabirov Date: Thu, 14 Nov 2024 15:45:17 +0200 Subject: [PATCH 3/3] pr fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0641016a..cf6c0f9f 100644 --- a/README.md +++ b/README.md @@ -944,7 +944,7 @@ List domains = Arrays.asList("domain.com"); // Users logging in from thi SSOOIDCSettings oidcSettings = new SSOOIDCSettings(name, clientId, clientSecret, redirectUrl, authUrl, tokenUrl, userDataUrl, scope, grantType); try { - ss.configureSAMLSettingsByMetadata(tenantId, oidcSettings, domains); + ss.configureOIDCSettings(tenantId, oidcSettings, domains); } catch (DescopeException de) { // Handle the error }