我使用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
非常感謝您的幫助!