Skip to content

Commit

Permalink
fix sso settings in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ruvenzx committed Nov 14, 2024
1 parent f24cfbb commit 0f12d1d
Showing 1 changed file with 53 additions and 10 deletions.
63 changes: 53 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<your-cert-here>";
String idpMetadataUrl = "https://idp.com/metadata";
String redirectUrl = "https://my-app.com/handle-saml"; // Global redirect URL for SSO/SAML
List<String> 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<RoleMapping> 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<RoleMapping> 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<String> scope;
@JsonProperty("JWKsUrl")
private String jwksUrl;
private OIDCAttributeMapping userAttrMapping;
private Boolean manageProviderTokens;
private String callbackDomain;
private List<String> prompt;
private String grantType;
private String issuer;
}

// Configure SSO - OIDC
String name = "Provider"; // Name of the provider
String clientId = "<oidc-client-id>"; // The client id set on the IdP
String clientSecret = "<oidc-client-secret>"; // 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<String> scope = Arrays.asList("openid", "profile"); // The scopes
String grantType = "implicit"; // The grant type
List<String> 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
}
Expand Down

0 comments on commit 0f12d1d

Please sign in to comment.