Scrivio Interview library
ConceptIntermediate5 min read · updated 12 November 2026

What is Spring Authorization Server, what are its main configuration pieces, and when would you run it instead of buying an identity provider?

Spring Authorization Server is a framework, built on Spring Security, that implements the OAuth 2.1 and OpenID Connect provider endpoints, so our own Spring application can issue tokens. Its main pieces are the RegisteredClientRepository, the OAuth2AuthorizationService, the consent service, a JWKSource for signing keys and token and client settings, with OAuth2TokenCustomizer for custom claims. We run it when we need deep customisation or an embedded server and have people to operate and secure it; otherwise a managed identity provider gives MFA, user management and compliance ready-made.

Why this question is asked

Most teams use OAuth2 as clients and resource servers. Sooner or later someone asks whether we could be the authorization server ourselves, perhaps to issue tokens for internal services, to embed login into a product, or to add claims no vendor supports. Interviewers ask this to see whether we know what Spring Authorization Server actually gives us, what we must still build, and when running it is a good idea. In this answer, we will see what it is, go through its configuration pieces with code, customise a token, and then compare running it with buying an identity provider.

1What Spring Authorization Server Is

An authorization server is the component that logs users in, asks for consent and issues tokens. It exposes standard endpoints: authorization, token, introspection, revocation, the JWKS with its public keys, and, for OpenID Connect, discovery and user info.

Spring Authorization Server implements those endpoints for the OAuth 2.1 draft and OpenID Connect 1.0 as filters on top of Spring Security. It started as a separate project, and in Spring Security 7 it ships as part of Spring Security itself, so the Maven coordinates and package versions depend on the release we use; check your version. Spring Boot offers a starter that auto-configures it.

Notice what it is not. It is a framework, not a product. It does not include a user database, an admin console, MFA, self-service password reset or a login page we would show to customers. We supply those.

2The Main Configuration Pieces

The server needs to know its clients, remember the authorizations it granted, remember consents, and sign tokens. Each of these is a bean we can replace.

Java
@Bean
RegisteredClientRepository clients(JdbcTemplate jdbc) {
RegisteredClient web = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("shop-web")
.clientSecret("{bcrypt}$2a$10$...") // stored hashed
.clientAuthenticationMethod(ClientAuthenticationMethod.CLIENT_SECRET_BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN)
.redirectUri("https://shop.example.com/login/oauth2/code/shop")
.scope(OidcScopes.OPENID).scope("orders.read")
.clientSettings(ClientSettings.builder().requireProofKey(true).requireAuthorizationConsent(true).build())
.tokenSettings(TokenSettings.builder().accessTokenTimeToLive(Duration.ofMinutes(10)).build())
.build();
var repo = new JdbcRegisteredClientRepository(jdbc);
if (repo.findByClientId("shop-web") == null) repo.save(web);
return repo;
}
@Bean
OAuth2AuthorizationService authorizations(JdbcTemplate jdbc, RegisteredClientRepository clients) {
return new JdbcOAuth2AuthorizationService(jdbc, clients); // codes, tokens, refresh tokens
}
@Bean
OAuth2AuthorizationConsentService consents(JdbcTemplate jdbc, RegisteredClientRepository clients) {
return new JdbcOAuth2AuthorizationConsentService(jdbc, clients); // which scopes a user approved
}
@Bean
JWKSource<SecurityContext> jwkSource(KeyStoreLoader keys) {
return new ImmutableJWKSet<>(new JWKSet(keys.currentRsaKey())); // published at the JWKS endpoint
}
Step throughA Spring Authorization Server application
  1. Protocol endpointsauthorize, token, introspect, revoke, JWKS, OIDC discovery
  2. Spring Security filtersclient authentication, user login, consent page
  3. Customisation hooksOAuth2TokenCustomizer, authentication providers
  4. StoresRegisteredClientRepository, AuthorizationService, ConsentService
  5. Keys and settingsJWKSource, AuthorizationServerSettings, token settings
  6. Things we supplyuser store, MFA, admin UI, monitoring

6 layers, from the top down. Step through them one at a time.

The framework provides the top layers; the bottom one is ours to build and run.

The RegisteredClientRepository holds every client with its grant types, redirect URIs, scopes and settings; the in-memory version is for demos, the JDBC one for real use. The OAuth2AuthorizationService stores issued authorization codes and tokens, which the server needs for refresh, revocation and introspection, so with more than one instance it must be shared, for example in a database. The consent service remembers what each user approved. The JWKSource holds the signing keys, and AuthorizationServerSettings sets the issuer URL and endpoint paths. ClientSettings and TokenSettings tune each client, such as requiring PKCE or setting token lifetimes.

3Adding Custom Claims

A common reason to run our own server is to put claims into tokens that come from our own systems, such as a tenant id. OAuth2TokenCustomizer<JwtEncodingContext> is called before each JWT is signed.

Java
@Bean
OAuth2TokenCustomizer<JwtEncodingContext> tenantClaim(TenantLookup tenants) {
return context -> {
if (OAuth2TokenType.ACCESS_TOKEN.equals(context.getTokenType())) {
String user = context.getPrincipal().getName();
context.getClaims().claim("tenant_id", tenants.tenantOf(user)); // e.g. "t-981"
}
};
}

We check the token type because the same customizer also runs for ID tokens, and the two often need different claims.

4When to Run It and When to Buy

Running Spring Authorization Server makes sense when we need things a product does not give us: tokens with unusual claims or grant types, an authorization server embedded inside a product we ship to customers, strict control over where data lives, or a machine-to-machine token service for internal systems where users never log in. In those cases its extensibility is the point, and we have Spring skills already.

The catch is that an identity provider is a security-critical system that must be up whenever anyone logs in. With our own server, we own patching, key management, high availability, brute-force protection, MFA, account recovery, audit logs and compliance evidence, and we need people who can do that for years. A managed identity provider gives MFA, passkeys, user management, anomaly detection and certifications ready-made, at a price per user. For a typical workforce or customer login with standard needs, buying is usually cheaper once we count the staff.

5Follow-up questions

Does Spring Authorization Server include a user database?

No. Users are authenticated by ordinary Spring Security, so we plug in a UserDetailsService, an LDAP directory or an upstream login such as social login. Everything around users, sign-up, password reset, MFA enrolment, is ours to build.

Can it act as a token service only for machine clients?

Yes, and that is one of its simplest uses. With only client credentials clients there is no login page or consent, and the main work is client management and key rotation.

What has to be shared when we run several instances?

The client repository, the authorization service and the consent service must use a shared store such as a database, and every instance must sign with the same keys from the same JWKSource, otherwise a refresh or an introspection may hit an instance that knows nothing about the token.

6Conclusion

In this answer, we saw that Spring Authorization Server implements the OAuth 2.1 and OpenID Connect provider endpoints on Spring Security, and in Spring Security 7 it is part of Spring Security. Its pieces are the RegisteredClientRepository, the authorization and consent services, the JWKSource and the server, client and token settings, and OAuth2TokenCustomizer adds custom claims. It suits deep customisation or embedding when we can operate it securely; a managed identity provider brings MFA, user management and compliance without that work.

What to say in the interviewAbout 80 seconds aloud

Open with

Spring Authorization Server is a Spring Security based framework that implements the authorization server side of OAuth 2.1 and OpenID Connect: the authorize and token endpoints, introspection and revocation, the JWKS and discovery.

Then, if they want more

It used to be a separate project; with Spring Security 7 it ships inside Spring Security, so I would check the coordinates for our version.

The main pieces I configure are the RegisteredClientRepository, usually the JDBC one, holding each client's grant types, redirect URIs, scopes and settings such as requiring PKCE; the OAuth2AuthorizationService, which stores codes and tokens and must be shared across instances; the consent service; a JWKSource with the signing keys; and AuthorizationServerSettings and token settings for the issuer and lifetimes.

To add claims, I register an OAuth2TokenCustomizer for JwtEncodingContext, for example to add a tenant id to access tokens. It is a framework, not a product: there is no user store, admin console or MFA.

So I would run it when we need deep customisation, an embedded server in our product, or a machine-to-machine token service, and when we have people to operate and secure it long term. For standard workforce or customer login, a managed identity provider usually wins because MFA, user management and compliance come ready.

About this answer

Last updated
12 November 2026
Versions it names
Spring Security 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is Spring Authorization Server, what are its main configuration pieces, and when...": https://scrivio-interview-library.netlify.app/spring-boot/oauth2-and-oidc/62677cd585/