Skip to content

Example Spring Boot app demonstrating Scalekit authentication using OpenID Connect. Shows login, callback, logout, and protected pages with Spring Security

Notifications You must be signed in to change notification settings

scalekit-inc/scalekit-springboot-auth-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Scalekit Authentication Example

A simple Spring Boot app that shows how to add secure sign-in with Scalekit (OIDC). You can it as a starting point or as a reference to integrate enterprise-grade authentication.

What this example includes:

  • The app signs users in with Scalekit using the OpenID Connect (OIDC) authorization flow.
  • The /dashboard page is protected by Spring Security and redirects unauthenticated users to the login flow.
  • The security configuration shows how to register an OAuth 2.0 client and wire login, callback, and logout endpoints.
  • The Thymeleaf templates use Bootstrap classes so pages render well on desktop and mobile.
  • After login, the dashboard displays selected ID token claims to demonstrate how to access user information.

Prerequisites

  • Java 17 or later is installed.
  • Maven 3.6 or later is installed.
  • You have a Scalekit account with an OIDC application. Sign up

🛠️ Quick start

Configure Scalekit

Pick one method below.

Method A — application-local.properties (recommended for local dev):

Create or update src/main/resources/application-local.properties:

# Replace placeholders with your values
scalekit.env-url=https://your-env.scalekit.io
scalekit.client-id=YOUR_CLIENT_ID
scalekit.client-secret=YOUR_CLIENT_SECRET
scalekit.redirect-uri=http://localhost:8080/auth/callback

# Optional server config
server.port=8080

Method B — environment variables:

export SCALEKIT_ENV_URL=https://your-env.scalekit.io
export SCALEKIT_CLIENT_ID=YOUR_CLIENT_ID
export SCALEKIT_CLIENT_SECRET=YOUR_CLIENT_SECRET
export SCALEKIT_REDIRECT_URI=http://localhost:8080/auth/callback

Important:

  • Never commit secrets to source control.
  • Ensure the redirect URI exactly matches what is configured in Scalekit.

Build and run

# Build
mvn clean compile

# Run (default profile)
mvn spring-boot:run

# Or run with the local profile (uses application-local.properties)
mvn spring-boot:run -Dspring-boot.run.profiles=local

The application will start at http://localhost:8080

Setup Scalekit

To find your required values:

  1. Visit Scalekit Dashboard and proceed to Settings

  2. Copy the API credentails

    • Environment URL (e.g., https://your-env.scalekit.dev)
    • Client ID
    • Client Secret
  3. Authentication > Redirect URLs > Allowed redirect URIs:

    • Add http://localhost:8080/auth/callback
    • Optionally add http://localhost:8080 as a post-logout redirect

Application routes

Route Description Auth required
/ Home page with login option No
/login Custom login page No
/dashboard Protected dashboard Yes
/oauth2/authorization/scalekit Start the OIDC flow No
/auth/callback OIDC callback No
/logout Logout and end session Yes

🚦 Try the app

  1. Start the app (see Quick start)
  2. Visit http://localhost:8080
  3. Click Sign in with Scalekit
  4. Authenticate with your provider
  5. Open the dashboard and then try logout

Stuck? Contact us.

Enable debug logging

Add this to src/main/resources/application.yml:

logging:
  level:
    com.example.scalekit: DEBUG
    org.springframework.security: DEBUG
    org.springframework.security.oauth2: TRACE

Code structure

src/
├── main/
│   ├── java/com/example/scalekit/
│   │   ├── ScalekitDemoApplication.java    # Main application class
│   │   ├── config/
│   │   │   ├── ScalekitConfig.java         # Scalekit client configuration
│   │   │   └── SecurityConfig.java         # Spring Security configuration
│   │   └── controller/
│   │       ├── HomeController.java         # Home and login endpoints
│   │       └── DashboardController.java    # Protected endpoints
│   └── resources/
│       ├── application.yml                 # Main configuration
│       ├── application-local.properties    # Local configuration
│       └── templates/                      # Thymeleaf templates
│           ├── index.html                  # Home page
│           ├── login.html                  # Login page
│           ├── dashboard.html              # User dashboard
│           └── layout.html                 # Base layout
└── test/                                   # Test files

Dependencies

  • Spring Boot
  • Spring Security (OAuth 2.0 Client)
  • Scalekit SDK
  • Thymeleaf
  • Bootstrap (via CDN)

See pom.xml for exact versions.

Support

License 📄

This project is for demonstration and learning. Refer to dependency licenses for production use.

About

Example Spring Boot app demonstrating Scalekit authentication using OpenID Connect. Shows login, callback, logout, and protected pages with Spring Security

Topics

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •