This is a companion sample for the Auth0 Servlet library. Please refer to that library and documentation for further information specific to the library itself.
A simple (plain) Java web application that demonstrates how to use Auth0 with Java for server-side MVC web apps. Validates the JWT from Auth0 in every API call to assert authentication according to configuration. If your application only needs secured endpoints and the ability to programmatically work with a Principal object for GrantedAuthority checks this library is a good fit.
However, if you are already using Java Spring and wish to leverage fully Java Spring Security - with powerful support for Security Annotations, Security JSTL Tag libraries, Fine-grained Annotation level method security and URL endpoint security at the Role / Group level - then see this project Auth0 Spring Security MVC and associated sample Auth0 Spring Security MVC Sample
If you are not ready for Java Spring Security yet, but would prefer to be using Java Spring (Boot), and leverage the benefits of convention over configuration, dependency injection and so on, then this project Auth0 Spring MVC and associated sample Auth0 Spring MVC Sample
In order to run this example you will need to have Java 7+ and Maven installed.
Check that your maven version is 3.0.x or above:
mvn -v
Create an Auth0 Account (if not already done so - free!).
Create an application - for the purposes of this sample - app
Ensure you add the following to the settings.
Allowed Callback URL:
http://localhost:3099/callback
Ensure you add the following to the settings.
Allowed Logout URLs:
http://localhost:3099/logout
Add one or more connections
to your application - for instance Google Social Connection,
or username-password DB connection.
Enter your:
auth0.domain
, auth0.issuer
, auth0.clientId
, and auth0.clientSecret
into src/main/webapp/WEB-INF/web.xml
Note:
auth0.issuer
should have the value https://YOUR_DOMAIN/
(the trailing slash is important).
For example, if your auth0.domain
is example.auth0.com
then auth0.issuer
should have value https://example.auth0.com/
.
In order to build and run the project you must execute:
mvn clean install tomcat7:run
Then, go to http://localhost:3099/login.