Loading...
Loading...
Use when securing Spring Boot API endpoints with JWT Bearer token validation, scope-based authorization, or DPoP proof-of-possession - integrates com.auth0:auth0-springboot-api SDK for REST APIs receiving access tokens from frontends or mobile apps. Triggers on Auth0AuthenticationFilter, Spring Boot API auth, JWT validation, SecurityFilterChain, hasAuthority SCOPE.
npx skill4agent add auth0/agent-skills auth0-springboot-apicom.auth0:auth0-springboot-apiAgent instruction: Before providing SDK setup instructions, fetch the latest release version by running:bashgh api repos/auth0/auth0-auth-java/releases/latest --jq '.tag_name'Use the returned version in all dependency lines instead of any hardcoded version below. If the API call fails (e.g., no releases yet), use.1.0.0-beta.1
auth0-quickstart| Use Case | Recommended Skill |
|---|---|
| Server-rendered web applications (Spring MVC with sessions) | Use |
| Single Page Applications | Use |
| Mobile applications | Use |
| Non-Spring Java APIs | Use |
Agent instruction: If the user's prompt already provides Auth0 credentials (domain, audience), use them directly — skip the bootstrap script and credential questions. Only offer setup options when credentials are missing.
implementation 'com.auth0:auth0-springboot-api:1.0.0-beta.1'<dependency>
<groupId>com.auth0</groupId>
<artifactId>auth0-springboot-api</artifactId>
<version>1.0.0-beta.1</version>
</dependency>STOP — ask the user before proceeding.Ask exactly this question and wait for their answer before doing anything else:"How would you like to create the Auth0 API resource?
- Automated — I'll run Auth0 CLI scripts that create the resource and write the values to your application.yml automatically.
- Manual — You create the API yourself in the Auth0 Dashboard (or via
) and provide me the Domain and Audience.auth0 apis createWhich do you prefer? (1 = Automated / 2 = Manual)"Do NOT proceed to any setup steps until the user has answered. Do NOT default to manual.
application.yml# Using Auth0 CLI
auth0 apis create \
--name "My Spring Boot API" \
--identifier https://my-springboot-apiauth0:
domain: "your-tenant.auth0.com"
audience: "https://my-springboot-api"https://application.propertiesauth0.domain=your-tenant.auth0.com
auth0.audience=https://my-springboot-api@Configuration
@EnableMethodSecurity
public class SecurityConfig {
@Bean
SecurityFilterChain apiSecurity(
HttpSecurity http,
Auth0AuthenticationFilter authFilter
) throws Exception {
return http
.csrf(csrf -> csrf.disable())
.sessionManagement(session ->
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/public").permitAll()
.requestMatchers("/api/protected").authenticated()
.requestMatchers("/api/admin/**").hasAuthority("SCOPE_admin")
.anyRequest().authenticated())
.addFilterBefore(authFilter, UsernamePasswordAuthenticationFilter.class)
.build();
}
}@RestController
@RequestMapping("/api")
public class ApiController {
@GetMapping("/public")
public ResponseEntity<Map<String, Object>> publicEndpoint() {
return ResponseEntity.ok(Map.of("message", "Public endpoint - no token required"));
}
@GetMapping("/protected")
public ResponseEntity<Map<String, Object>> protectedEndpoint(Authentication authentication) {
Auth0AuthenticationToken token = (Auth0AuthenticationToken) authentication;
return ResponseEntity.ok(Map.of(
"user", authentication.getName(),
"email", token.getClaim("email"),
"scopes", token.getScopes()
));
}
}Agent instruction: After writing all code, verify the build succeeds:bash./gradlew bootRunor. If build fails, diagnose and fix. After 5-6 failed attempts, use./mvnw spring-boot:runto get help.AskUserQuestion
curl http://localhost:8080/api/publiccurl http://localhost:8080/api/protected \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"| Mistake | Fix |
|---|---|
Domain includes | Use |
| Audience doesn't match API Identifier | Must exactly match the API Identifier set in Auth0 Dashboard |
| Created Application instead of API in Auth0 | Must create API resource in Auth0 Dashboard → Applications → APIs |
Missing | |
| Using ID token instead of access token | Must use access token for API auth, not ID token |
Checking | Scopes map to |
| Spring Boot env var binding | Use |
@PreAuthorizeauth0-quickstartauth0-javaapplication.ymlauth0.domainhttps://auth0.audienceauth0.dpop-modeDISABLEDALLOWEDREQUIREDauth0.dpop-iat-offset-secondsauth0.dpop-iat-leeway-secondsAuth0AuthenticationTokenauthentication.getName()subtoken.getClaim("email")token.getClaims()Map<String, Object>token.getScopes()Set<String>requestMatchers("/path").authenticated()hasAuthority("SCOPE_read:data")@PreAuthorize