Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.
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
4 changes: 2 additions & 2 deletions java-sso-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 38 additions & 7 deletions java-sso-example/src/main/jte/home.jte
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
<link rel="stylesheet" href="main.css">

<body class="container_login">
<div class='flex_column'>
<div class="flex heading_div">
<img src="images/workos-logo-with-text.png" alt="workos logo">
</div>
<body class="height-100vh">
<div class="logged_in_nav">
<div class="flex">
<div>
<img src="images/workos-logo-with-text.png" alt="workos logo">
</div>

<h2>Java SSO Example App</h2>
<a class="button login_button" href="/login">Login</a>
</div>
<div class="flex">
<a href="https://workos.com/docs" target="_blank"><button class='button nav-item'>Documentation</button></a>
<a href="https://workos.com/docs/reference" target="_blank"><button class='button nav-item'>API
Reference</button></a>
<a href="https://workos.com/blog" target="_blank"><button
class='button nav-item blog-nav-button'>Blog</button></a>
<a href="https://workos.com/" target="_blank"><button class='button button-outline'>WorkOS</button></a>
</div>
</div>
<div class="flex flex_column height-80vh">
<div class='flex height-40vh'>
<div class="card height-315 width-335">
<form method="POST" action="/login" class="mb-0">
<div class='flex_column'>
<div>
<span>Log in with SSO</span>
</div>
<hr style="width:100%; margin-top: 15px; margin-bottom: 20px;">
<button id="Google" name="login_method" value="GoogleOAuth" class="card login_button google_button">
<span>Google OAuth</span>
</button>
<button id="Microsoft" name="login_method" value="MicrosoftOAuth" class="card login_button microsoft_button">
<span>Microsoft OAuth</span>
</button>
<button id="SAML" name="login_method" value="saml" class="card login_button saml_button mb-0">
<span>Enterprise SAML</span>
</button>
</div>
</form>
</div>
</div>
</div>
</body>
21 changes: 3 additions & 18 deletions java-sso-example/src/main/jte/profile.jte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
<div class="logged_in_nav">
<div class="flex">
<div>
<img src="/images/workos-logo-with-text.png" alt="workos logo">
<img src="images/workos-logo-with-text.png" alt="workos logo">
</div>

</div>
<div>
<div class="flex">
<a href="https://workos.com/docs" target="_blank"><button class='button nav-item'>Documentation</button></a>
<a href="https://workos.com/docs/reference" target="_blank"><button class='button nav-item'>API
Reference</button></a>
Expand All @@ -19,22 +20,6 @@
</div>
</div>
<div class='flex'>
<div class="logged_in_div_left">
<div class="title-text">
<h1>Your app,</h1>
<h2 class="home-hero-gradient">Enterprise Ready</h2>
</div>
<div class="title-subtext">
<p>Start selling to enterprise customers with just a few lines of code.</p>
<p>Implement features like single sign-on in minutes instead of months.</p>
</div>
<div class="flex success-buttons">
<a href="https://workos.com/signup" target="_blank"><button class='button'>Get Started</button></a>
<a href="mailto:sales@workos.com?subject=WorkOS Sales Inquiry" target="_blank"><button
class='button button-outline sales-button'>Contact
Sales</button></a>
</div>
</div>
<div class="logged_in_div_right">
<div class="flex_column">
<table class="table">
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading