Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Commit a7f99df

Browse files
awolfdenAdam Wolfman
andauthored
Update java sso app with new UI/UX (#47)
Co-authored-by: Adam Wolfman <adamwolfman@Adams-MBP-3.domain>
1 parent 249d141 commit a7f99df

8 files changed

Lines changed: 344 additions & 191 deletions

File tree

java-sso-example/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ The .env file is listed in this repo's .gitignore file, so your sensitive inform
5151

5252
## Set up SSO with WorkOS
5353
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.
54-
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:
54+
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:
5555
```bash
5656
WORKOS_API_KEY=your_api_key_here
5757
WORKOS_CLIENT_ID=your_project_id_here
58-
WORKOS_CONNECTION_ID=your_connection_id_here
58+
WORKOS_ORGANIZATION_ID=your_organization_id_here
5959
```
6060

6161
10. Add http://localhost:7001/callback as the default Redirect URI in the Configuration section of the WorkOS Dashboard:

java-sso-example/src/main/java/com/workos/java/examples/SsoApp.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,33 @@ public SsoApp() {
2525
clientId = env.get("WORKOS_CLIENT_ID");
2626

2727
app.get("/", this::isLoggedIn);
28-
app.get("/login", this::login);
28+
app.post("/login", this::login);
2929
app.get("/callback", this::callback);
3030
app.get("logout", this::logout);
3131
}
3232

3333
public void login(Context ctx) {
3434
Dotenv env = Dotenv.configure().directory("../.env").load();
35-
String connectionId = env.get("WORKOS_CONNECTION_ID");
36-
String url =
37-
workos
38-
.sso
39-
.getAuthorizationUrl(clientId, "http://localhost:7001/callback")
40-
.connection(connectionId)
41-
.build();
35+
String organizationId = env.get("WORKOS_ORGANIZATION_ID");
36+
String loginType = ctx.formParam("login_method");
4237

43-
ctx.redirect(url);
38+
if (loginType.equals("saml")) {
39+
String url =
40+
workos
41+
.sso
42+
.getAuthorizationUrl(clientId, "http://localhost:7001/callback")
43+
.organization(organizationId)
44+
.build();
45+
ctx.redirect(url);
46+
} else {
47+
String url =
48+
workos
49+
.sso
50+
.getAuthorizationUrl(clientId, "http://localhost:7001/callback")
51+
.provider(loginType)
52+
.build();
53+
ctx.redirect(url);
54+
}
4455
}
4556

4657
public void callback(Context ctx) {
Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
<link rel="stylesheet" href="main.css">
22

3-
<body class="container_login">
4-
<div class='flex_column'>
5-
<div class="flex heading_div">
6-
<img src="images/workos-logo-with-text.png" alt="workos logo">
7-
</div>
3+
<body class="height-100vh">
4+
<div class="logged_in_nav">
5+
<div class="flex">
6+
<div>
7+
<img src="images/workos-logo-with-text.png" alt="workos logo">
8+
</div>
89

9-
<h2>Java SSO Example App</h2>
10-
<a class="button login_button" href="/login">Login</a>
10+
</div>
11+
<div class="flex">
12+
<a href="https://workos.com/docs" target="_blank"><button class='button nav-item'>Documentation</button></a>
13+
<a href="https://workos.com/docs/reference" target="_blank"><button class='button nav-item'>API
14+
Reference</button></a>
15+
<a href="https://workos.com/blog" target="_blank"><button
16+
class='button nav-item blog-nav-button'>Blog</button></a>
17+
<a href="https://workos.com/" target="_blank"><button class='button button-outline'>WorkOS</button></a>
18+
</div>
19+
</div>
20+
<div class="flex flex_column height-80vh">
21+
<div class='flex height-40vh'>
22+
<div class="card height-315 width-335">
23+
<form method="POST" action="/login" class="mb-0">
24+
<div class='flex_column'>
25+
<div>
26+
<span>Log in with SSO</span>
27+
</div>
28+
<hr style="width:100%; margin-top: 15px; margin-bottom: 20px;">
29+
<button id="Google" name="login_method" value="GoogleOAuth" class="card login_button google_button">
30+
<span>Google OAuth</span>
31+
</button>
32+
<button id="Microsoft" name="login_method" value="MicrosoftOAuth" class="card login_button microsoft_button">
33+
<span>Microsoft OAuth</span>
34+
</button>
35+
<button id="SAML" name="login_method" value="saml" class="card login_button saml_button mb-0">
36+
<span>Enterprise SAML</span>
37+
</button>
38+
</div>
39+
</form>
40+
</div>
41+
</div>
1142
</div>
1243
</body>

java-sso-example/src/main/jte/profile.jte

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
<div class="logged_in_nav">
77
<div class="flex">
88
<div>
9-
<img src="/images/workos-logo-with-text.png" alt="workos logo">
9+
<img src="images/workos-logo-with-text.png" alt="workos logo">
1010
</div>
11+
1112
</div>
12-
<div>
13+
<div class="flex">
1314
<a href="https://workos.com/docs" target="_blank"><button class='button nav-item'>Documentation</button></a>
1415
<a href="https://workos.com/docs/reference" target="_blank"><button class='button nav-item'>API
1516
Reference</button></a>
@@ -19,22 +20,6 @@
1920
</div>
2021
</div>
2122
<div class='flex'>
22-
<div class="logged_in_div_left">
23-
<div class="title-text">
24-
<h1>Your app,</h1>
25-
<h2 class="home-hero-gradient">Enterprise Ready</h2>
26-
</div>
27-
<div class="title-subtext">
28-
<p>Start selling to enterprise customers with just a few lines of code.</p>
29-
<p>Implement features like single sign-on in minutes instead of months.</p>
30-
</div>
31-
<div class="flex success-buttons">
32-
<a href="https://workos.com/signup" target="_blank"><button class='button'>Get Started</button></a>
33-
<a href="mailto:sales@workos.com?subject=WorkOS Sales Inquiry" target="_blank"><button
34-
class='button button-outline sales-button'>Contact
35-
Sales</button></a>
36-
</div>
37-
</div>
3823
<div class="logged_in_div_right">
3924
<div class="flex_column">
4025
<table class="table">
5.68 KB
Loading
3.24 KB
Loading
4.87 KB
Loading

0 commit comments

Comments
 (0)