Spring oauth2 authorization server 0.4.2怎么配置
时间: 2023-09-13 07:07:01 浏览: 151
Spring oauth2 authorization server 0.4.2 的配置需要以下步骤:
1. 引入依赖:在 Maven pom.xml 文件中添加以下依赖
```
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-authorization-server</artifactId>
<version>0.4.2</version>
</dependency>
```
2. 配置 application.yml 文件:添加以下内容
```
spring:
security:
oauth2:
authorization:
server:
jwt:
jwk-set-uri: http://localhost:8080/.well-known/jwks.json
clients:
registration:
client-id:
provider: my-auth-server
client-id: client-id
client-secret: client-secret
authorization-grant-type: authorization_code
redirect-uri: http://localhost:8081/login/oauth2/code/my-auth-server
scope: read,write
```
3. 添加控制器:添加以下代码段
```
@Configuration
public class OAuth2AuthorizationServerConfig {
@Bean
public RegisteredClientRepository registeredClientRepository() {
RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString())
.clientId("client-id")
.clientSecret("client-secret")
.clientAuthenticationMethod(ClientAuthenticationMethod.BASIC)
.authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE)
.redirectUri("http://localhost:8081/login/oauth2/code/my-auth-server")
.scope("read", "write")
.build();
return new InMemoryRegisteredClientRepository(registeredClient);
}
}
```
以上是 Spring oauth2 authorization server 0.4.2 的基本配置,你可以根据自己的需要进行更改和扩展。
阅读全文