Skip to main content

Java / Spring quickstart

Java 17+, Spring Boot 3.x.

implementation 'com.latchvector:latchvector-sso-spring-boot-starter:1.0.0'

1. Protect an API — two properties

latchvector:
sso:
issuer: https://sso.yourdomain.com
audience: https://api.yourcompany.com # your registered identifier

The starter builds a JwtDecoder wired to the right validators, so an ordinary resource-server config works:

@Bean
SecurityFilterChain api(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
.oauth2ResourceServer(oauth -> oauth.jwt(Customizer.withDefaults()))
.build();
}

Controllers take a Principal directly, and method security (@PreAuthorize) sees the token's permissions as authorities.

2. Log a user in

SsoClient sso = new SsoClient(issuer, audience, 2, RestClient.create());
Object result = sso.login(email, password);
if (result instanceof TokenPair tokens) {
String access = tokens.accessToken();
String refresh = tokens.refreshToken();
}

3. Manage resources

ManagementClient mgmt = new ManagementClient(issuer, tokens::accessToken, 2, RestClient.create());
mgmt.createUser(Map.of("organizationId", orgId, "email", email, "fullName", name));
mgmt.createApplication(Map.of("organizationId", orgId, "identifier", identifier, "name", name));

Anything new is reachable via mgmt.request(...).

:::tip Full reference The starter README covers machine-to-machine, multitenancy (JPA/Hibernate), webhooks, and go-live checks. Full endpoint list: API reference. :::