Get Started
This quickstart demonstrates how to add Auth0 login to a Spring Boot web application. You’ll build a secure web app with login, logout, and a protected profile page using the Okta Spring Boot Starter, which auto-configures Spring Security’s OAuth2 login support.Create a new project
Generate a Spring Boot project with the required dependencies.
- Using Spring Initializr
- Or manually create with Maven
Add the Okta Spring Boot Starter
Add the Okta Spring Boot Starter dependency to your project. This pulls in Spring Security OAuth2 login support with Auth0/Okta-specific auto-configuration.
- Maven (pom.xml)
- Gradle (build.gradle)
Configure Auth0
Create a Regular Web Application in your Auth0 tenant and add the configuration to your project.You can choose to do this automatically by running a CLI command or do it manually via the Dashboard:
- CLI
- Dashboard
Run the following shell command on your project’s root directory to create an Auth0 application and update your
application.yml file:- Mac/Linux
- Windows (PowerShell)
Configure authentication
Create a security configuration that enables OAuth2 login and handles Auth0 logout. Unauthenticated users are redirected to the Auth0 login page automatically.
Create controllers and views
Create the controllers and the Thymeleaf templates for the home and profile pages.
You should now have a fully functional Spring Boot web application with Auth0 login running on your localhost. The home page is public, and navigating to
/profile redirects unauthenticated users to the Auth0 login page.Advanced Usage
Accessing User Profile Claims
Accessing User Profile Claims
The
@AuthenticationPrincipal OidcUser parameter gives you access to all claims from the ID token. Use getClaims() to retrieve the full set or individual getter methods for specific claims.Role-Based Access Control
Role-Based Access Control
You can restrict access to pages based on Auth0 roles. First, add roles to the ID token using an Auth0 Action, then use
hasAuthority() in your security configuration.Add Roles to Tokens
- Go to Auth0 Dashboard → Actions → Flows → Login.
- Create a custom Action that adds roles as a custom claim to the ID token:
Configure Authorization
Update yourSecurityConfig to require specific roles on endpoints:Custom Authority Mapping
Custom Authority Mapping
Common Issues
Redirect to login fails - Invalid callback URL
Redirect to login fails - Invalid callback URL
After selecting login, Auth0 shows an error about a callback URL mismatch.The Allowed Callback URLs in your Auth0 application must exactly match the callback URL used by Spring Security. The default is
http://localhost:3000/login/oauth2/code/okta.- Go to Auth0 Dashboard → Applications → Your App → Settings.
- Under Allowed Callback URLs, add:
http://localhost:3000/login/oauth2/code/okta. - Choose Save Changes.
Invalid issuer at startup
Invalid issuer at startup
The application fails to start or login fails with an issuer mismatch.The
okta.oauth2.issuer must be the full Auth0 tenant URL including https:// and a trailing /.OIDC discovery failure at startup
OIDC discovery failure at startup
The application fails to start with a connection error when fetching
/.well-known/openid-configuration.The Okta Spring Boot Starter fetches the OpenID Connect discovery document from your issuer URL at startup. Verify that the issuer URL is correct and reachable from your network. If behind a corporate firewall, configure the proxy:Configuration values not found
Configuration values not found
The application starts but login fails because configuration properties are not being read.Ensure your
application.yml uses the correct YAML indentation under the okta.oauth2 namespace:Logout does not clear Auth0 session
Logout does not clear Auth0 session
After selecting logout, the user is immediately logged back in without seeing the Auth0 login page.Ensure your
SecurityConfig includes the custom LogoutHandler that redirects to the Auth0 /v2/logout endpoint. Also verify that the Allowed Logout URLs in your Auth0 Application Settings includes http://localhost:3000/.Additional Resources
SDK Documentation
Complete SDK documentation, source code, and release notes
Auth0 Documentation
Official Auth0 documentation for Spring Boot applications
Spring Security Reference
Spring Security OAuth2 Login documentation
Configuration Reference
All available okta.oauth2.* configuration properties
Auth0 Dashboard
Manage your Auth0 APIs and applications
Community Forum
Get help from the Auth0 community
Sample Application
A complete sample application demonstrating login, profile display, and logout with Auth0 is available in the Auth0 samples repository.MVC Login Sample
Includes login, logout, and profile page with Auth0 OAuth2 integration
http://localhost:3000 in your browser and select the Login link to test the Auth0 login flow.