diff --git a/java-sso-example/README.md b/java-sso-example/README.md index c8410b6..186aef9 100644 --- a/java-sso-example/README.md +++ b/java-sso-example/README.md @@ -51,11 +51,11 @@ The .env file is listed in this repo's .gitignore file, so your sensitive inform ## Set up SSO with WorkOS 7. Create an [Organization](https://dashboard.workos.com/organizations) and an [SSO Connection](https://workos.com/docs/sso/guide/introduction) in the Organization in your WorkOS Dashboard. -8. Copy the Connection ID from the new connection that you just set up and add it to the same .env file that you created in step 6. The .env file should now look like this: +8. Copy the Organization ID from the organization that you just set up and add it to the same .env file that you created in step 6. The .env file should now look like this: ```bash WORKOS_API_KEY=your_api_key_here WORKOS_CLIENT_ID=your_project_id_here -WORKOS_CONNECTION_ID=your_connection_id_here +WORKOS_ORGANIZATION_ID=your_organization_id_here ``` 10. Add http://localhost:7001/callback as the default Redirect URI in the Configuration section of the WorkOS Dashboard: diff --git a/java-sso-example/src/main/java/com/workos/java/examples/SsoApp.java b/java-sso-example/src/main/java/com/workos/java/examples/SsoApp.java index d954c0e..0ee8052 100644 --- a/java-sso-example/src/main/java/com/workos/java/examples/SsoApp.java +++ b/java-sso-example/src/main/java/com/workos/java/examples/SsoApp.java @@ -25,22 +25,33 @@ public SsoApp() { clientId = env.get("WORKOS_CLIENT_ID"); app.get("/", this::isLoggedIn); - app.get("/login", this::login); + app.post("/login", this::login); app.get("/callback", this::callback); app.get("logout", this::logout); } public void login(Context ctx) { Dotenv env = Dotenv.configure().directory("../.env").load(); - String connectionId = env.get("WORKOS_CONNECTION_ID"); - String url = - workos - .sso - .getAuthorizationUrl(clientId, "http://localhost:7001/callback") - .connection(connectionId) - .build(); + String organizationId = env.get("WORKOS_ORGANIZATION_ID"); + String loginType = ctx.formParam("login_method"); - ctx.redirect(url); + if (loginType.equals("saml")) { + String url = + workos + .sso + .getAuthorizationUrl(clientId, "http://localhost:7001/callback") + .organization(organizationId) + .build(); + ctx.redirect(url); + } else { + String url = + workos + .sso + .getAuthorizationUrl(clientId, "http://localhost:7001/callback") + .provider(loginType) + .build(); + ctx.redirect(url); + } } public void callback(Context ctx) { diff --git a/java-sso-example/src/main/jte/home.jte b/java-sso-example/src/main/jte/home.jte index 971ac24..261b32b 100644 --- a/java-sso-example/src/main/jte/home.jte +++ b/java-sso-example/src/main/jte/home.jte @@ -1,12 +1,43 @@ -
-
-
+
Start selling to enterprise customers with just a few lines of code.
-Implement features like single sign-on in minutes instead of months.
-