If you are just getting started with Spring Authorization Server, the following sections walk you through creating your first application.
Spring Authorization Server can be used anywhere you already use Spring Security.
The easiest way to begin using Spring Authorization Server is by creating a Spring Boot-based application. You can use start.spring.io to generate a basic project or use the default authorization server sample as a guide. Then add Spring Boot’s starter for Spring Authorization Server as a dependency:
- Maven
-
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-authorization-server</artifactId> </dependency>
- Gradle
-
implementation "org.springframework.boot:spring-boot-starter-oauth2-authorization-server"
Tip
|
See Installing Spring Boot for more information on using Spring Boot with Maven or Gradle. |
Alternatively, you can add Spring Authorization Server without Spring Boot using the following example:
- Maven
-
<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-oauth2-authorization-server</artifactId> <version>{spring-authorization-server-version}</version> </dependency>
- Gradle
-
implementation "org.springframework.security:spring-security-oauth2-authorization-server:{spring-authorization-server-version}"
To get started, you need the minimum required components defined as a @Bean
. When using the spring-boot-starter-oauth2-authorization-server
dependency, define the following properties and Spring Boot will provide the necessary @Bean
definitions for you:
link:{docs-java}/sample/gettingstarted/application.yml[role=include]
Tip
|
Beyond the Getting Started experience, most users will want to customize the default configuration. The next section demonstrates providing all of the necessary beans yourself. |
If you want to customize the default configuration (regardless of whether you’re using Spring Boot), you can define the minimum required components as a @Bean
in a Spring @Configuration
.
These components can be defined as follows:
link:{docs-java}/sample/gettingstarted/SecurityConfig.java[role=include]
This is a minimal configuration for getting started quickly. To understand what each component is used for, see the following descriptions:
-
A Spring Security filter chain for the Protocol Endpoints.
-
A Spring Security filter chain for authentication.
-
An instance of javadoc:org.springframework.security.core.userdetails.UserDetailsService[] for retrieving users to authenticate.
-
An instance of
RegisteredClientRepository
for managing clients. -
An instance of
com.nimbusds.jose.jwk.source.JWKSource
for signing access tokens. -
An instance of
java.security.KeyPair
with keys generated on startup used to create theJWKSource
above. -
An instance of javadoc:org.springframework.security.oauth2.jwt.JwtDecoder[] for decoding signed access tokens.
-
An instance of
AuthorizationServerSettings
to configure Spring Authorization Server.