很长一段时间以来,我想使用Spring Security集成一个OpenID Connect提供程序。上次尝试时,我感到它非常复杂,并编写了自己的库。由于Spring Security 5对OAuth2 Client具有本机支持,并且扩展了其对OpenID connect的使用,因此我想了解它的集成有多么容易。
对于此示例,我们将构建一个简单的应用程序,当我们试图访问受保护的端点时,会重定向到google
第1步:
从https://start.spring.io创建一个具有以下依赖项的spring boot项目
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-