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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tenant Multi Domain #90

Merged
merged 2 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -885,10 +885,10 @@ String idpUrl = "https://idp.com";
String entityId = "my-idp-entity-id";
String idpCert = "<your-cert-here>";
String redirectUrl = "https://my-app.com/handle-saml"; // Global redirect URL for SSO/SAML
String domain = "domain.com"; // Users logging in from this domain will be logged in to this tenant
List<String> domains = Arrays.asList("domain.com"); // Users logging in from this domain will be logged in to this tenant

try {
ss.configureSettings(tenantId, idpUrl, idpCert, entityId, redirectUrl, domain);
ss.configureSettings(tenantId, idpUrl, idpCert, entityId, redirectUrl, domains);
} catch (DescopeException de) {
// Handle the error
}
Expand Down Expand Up @@ -1204,6 +1204,7 @@ export DESCOPE_MANAGEMENT_KEY=<ManagementKey>
```

Alternatively, you can create a `.env` file in the working folder with your project ID and management key.

```
DESCOPE_PROJECT_ID=<ProjectID>
DESCOPE_MANAGEMENT_KEY=<ManagementKey>
Expand Down Expand Up @@ -1241,6 +1242,7 @@ To run Run and Debug using Visual Studio Code open the examples folder and run t

Java provides a very simple way to mock services and objects using the Mockito package.
Here is a simple example of how you can mock a magic link verify response.

```java
User user = new User("someUserName", MOCK_EMAIL, "+1-555-555-5555");
ApiProxy apiProxy = mock(ApiProxy.class); // Mock the proxy that actually sends the HTTP requests
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/descope/model/sso/SSOSettingsResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public class SSOSettingsResponse {
private UserMapping userMapping;
private List<GroupsMapping> groupsMapping;
private String redirectURL;
private List<String> domains;
// Deprecated - use domains instead
private String domain;
}
2 changes: 1 addition & 1 deletion src/main/java/com/descope/sdk/mgmt/SsoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface SsoService {
void deleteSettings(String tenantID) throws DescopeException;

void configureSettings(String tenantID, String idpURL, String idpCert, String entityID,
String redirectURL, String domain) throws DescopeException;
String redirectURL, List<String> domains) throws DescopeException;

void configureMetadata(String tenantID, String idpMetadataURL) throws DescopeException;

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/descope/sdk/mgmt/impl/SsoServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void configureSettings(
String idpCert,
String entityID,
String redirectURL,
String domain)
List<String> domains)
throws DescopeException {
if (StringUtils.isBlank(tenantID)) {
throw ServerCommonException.invalidArgument("TenantID");
Expand All @@ -69,7 +69,7 @@ public void configureSettings(
if (StringUtils.isBlank(redirectURL)) {
throw ServerCommonException.invalidArgument("RedirectURL");
}
Map<String, String> request =
Map<String, Object> request =
mapOf(
"tenantId",
tenantID,
Expand All @@ -81,8 +81,8 @@ public void configureSettings(
entityID,
"redirectURL",
redirectURL,
"domain",
domain);
"domains",
domains);
ApiProxy apiProxy = getApiProxy();
apiProxy.post(getUri(SSO_CONFIGURE_SETTINGS_LINK), request, Void.class);
}
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/com/descope/sdk/mgmt/impl/SsoServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void testConfigureSettingsForEmptyTenantId() {
ServerCommonException.class,
() ->
ssoService.configureSettings(
"", "idpUrl", "idpCert", "entryId", "redirectUrl", "domain"));
"", "idpUrl", "idpCert", "entryId", "redirectUrl", Arrays.asList("domain.com")));
assertNotNull(thrown);
assertEquals("The TenantID argument is invalid", thrown.getMessage());
}
Expand All @@ -98,7 +98,7 @@ void testConfigureSettingsForEmptyIdpURL() {
ServerCommonException.class,
() ->
ssoService.configureSettings(
"someTenantID", "", "idpCert", "entryId", "redirectUrl", "domain"));
"someTenantID", "", "idpCert", "entryId", "redirectUrl", Arrays.asList("domain.com")));
assertNotNull(thrown);
assertEquals("The IdpURL argument is invalid", thrown.getMessage());
}
Expand All @@ -110,7 +110,7 @@ void testConfigureSettingsForEmptyIdpCert() {
ServerCommonException.class,
() ->
ssoService.configureSettings(
"someTenantID", "idpUrl", "", "entryId", "redirectUrl", "domain"));
"someTenantID", "idpUrl", "", "entryId", "redirectUrl", Arrays.asList("domain.com")));
assertNotNull(thrown);
assertEquals("The IdpCert argument is invalid", thrown.getMessage());
}
Expand All @@ -122,7 +122,7 @@ void testConfigureSettingsForEmptyEntityID() {
ServerCommonException.class,
() ->
ssoService.configureSettings(
"someTenantID", "idpUrl", "idpCert", "", "redirectUrl", "domain"));
"someTenantID", "idpUrl", "idpCert", "", "redirectUrl", Arrays.asList("domain.com")));
assertNotNull(thrown);
assertEquals("The EntityID argument is invalid", thrown.getMessage());
}
Expand All @@ -134,7 +134,7 @@ void testConfigureSettingsForEmptyRedirectURL() {
ServerCommonException.class,
() ->
ssoService.configureSettings(
"someTenantID", "idpUrl", "idpCert", "entryId", "", "domain"));
"someTenantID", "idpUrl", "idpCert", "entryId", "", Arrays.asList("domain.com")));
assertNotNull(thrown);
assertEquals("The RedirectURL argument is invalid", thrown.getMessage());
}
Expand All @@ -147,7 +147,7 @@ void testConfigureSettingsForSuccess() {
mockedApiProxyBuilder.when(
() -> ApiProxyBuilder.buildProxy(any(), any())).thenReturn(apiProxy);
ssoService.configureSettings(
"someTenantID", "idpUrl", "idpCert", "entryId", "redirectUrl", "domain");
"someTenantID", "idpUrl", "idpCert", "entryId", "redirectUrl", Arrays.asList("domain.com"));
verify(apiProxy, times(1)).post(any(), any(), any());
}
}
Expand Down