给我一份spring boot 配置 oauth2 的配置
时间: 2023-02-14 08:34:10 浏览: 120
spring boot oauth2
在 Spring Boot 中配置 OAuth2 主要分为以下几步:
1. 在 pom.xml 中添加 Spring Security OAuth2 的依赖。
```xml
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.5.0.RELEASE</version>
</dependency>
```
2. 创建配置类并继承 `AuthorizationServerConfigurerAdapter`,进行认证服务器相关配置。
```java
@Configuration
@EnableAuthorizationServer
public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdapter {
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private TokenStore tokenStore;
@Autowired
private AccessTokenConverter accessTokenConverter;
@Autowired
private AuthorizationCodeServices authorizationCodeServices;
@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
private TokenEnhancer tokenEnhancer;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private WebResponseExceptionTranslator webResponseExceptionTranslator;
@Autowired
private TokenGranter tokenGranter;
@Autowired
private TokenServices tokenServices;
@Autowired
private TokenStore tokenStore;
@Autowired
private TokenEnhancer tokenEnhancer;
@Autowired
private TokenGranter tokenGranter;
@Autowired
private TokenServices tokenServices;
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
private AuthorizationCodeServices authorizationCodeServices;
@Autowired
private WebResponseExceptionTranslator webResponseExceptionTranslator;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private AccessTokenConverter accessTokenConverter;
@Autowired
private TokenStore tokenStore;
@Autowired
private TokenEnhancer tokenEnhancer;
@Autowired
private TokenGranter tokenGranter;
@Autowired
private TokenServices tokenServices;
@Autowired
private AuthenticationManager authenticationManager;
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private ClientDetailsService clientDetailsService;
@Autowired
private AuthorizationCodeServices authorizationCodeServices;
@Autowired
private WebResponseExceptionTranslator webResponseExceptionTranslator;
@Autowired
private PasswordEncoder passwordEncoder;
@Autowired
private AccessTokenConverter accessToken
阅读全文