通过 Spring Security OAuth2 重用最终用户 Google 身份验证来访问 Web 应用程序中的 Google Calendar API
我能够通过 Spring Security 登录创建一个小型 Spring Boot Web 应用程序
spring:
security:
oauth2:
client:
registration:
google:
client-id: <id>
client-secret: <secret>
scope:
- email
- profile
- https://www.googleapis.com/auth/calendar.readonly
Run Code Online (Sandbox Code Playgroud)
当应用程序启动时,我可以访问http://localhost:8080/user并要求用户登录谷歌。成功登录后,配置文件 json 将作为以下响应显示在浏览器中:
@RestController
class SecurityController {
@RequestMapping("/user")
fun user(principal: Principal): Principal {
return principal
}
}
Run Code Online (Sandbox Code Playgroud)
@Configuration
class SecurityConfiguration : WebSecurityConfigurerAdapter() {
@Throws(Exception::class)
override fun configure(http: HttpSecurity) {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login()
}
}
Run Code Online (Sandbox Code Playgroud)
google-calendar-api google-oauth spring-boot spring-security-oauth2 google-signin