我使用Spring Boot,Spring MVC和spring-security-oauth2创建网站,并试图通过Google,Facebook,GitHub ...验证本地存储的用户... OAuth2服务。我也有标准的用户名 - 密码。Spring Boot OAuth2 - 使用本地用户数据库与Facebook进行身份验证
我的想法是将每个用户的[OAuth2_provider_type,OAuth2_subjectId]对从第一次成功oauth登录存储到本地数据库,然后在用户通过Google(或FB ...)进行身份验证时使用此对来查找正确的用户。再次。我已经正确地使用Google/Facebook进行身份验证,但是我不知道如何将本地存储的用户连接到Spring OAuth2安全性并将它们传递给SecurityContext。
有人能指点我一些例子或集成测试,我可以看到类似的东西吗?
在这里,我发现伟大的教程Spring Boot and OAuth2与提示如何添加本地用户数据库。试图从重定向到谷歌授权的重新导向URI这就好比.antMatchers("/user").authenticated()
定义http://localhost:10001/user
终点并获得拒绝访问
o.s.s.w.a.i.FilterSecurityInterceptor - Secure object: FilterInvocation: URL: /user?state=Wj7RVk&code=4/wa2AFtJr0K3cKTxDAYo8rTOu2p41km5o3YCPnimx4wU; Attributes: [authenticated] o.s.s.w.a.i.FilterSecurityInterceptor - Previously Authenticated: org.sprin[email protected]6fa8940c: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]fffde5d4: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: 5888363FA9E329992073DCE4B21E8B5C; Granted Authorities: ROLE_ANONYMOUS o.s.s.access.vote.AffirmativeBased - Voter: org.sp[email protected]29802df4, returned: -1 o.s.s.w.a.ExceptionTranslationFilter - Access is denied (user is anonymous); redirecting to authentication entry point org.springframework.security.access.AccessDeniedException: Access is denied
非常感谢您的帮助!