我已经更新了我的项目到Symfony 6,现在我的谷歌登录不再像以前那样工作。如果关闭浏览器,记住我的令牌就不能工作。在5.4中,我的security.yaml是这样写的:
google:
pattern: ^/connect/google
guard:
authenticators:
- App\Security\GoogleAuthenticator
logout:
path: app_logout
target: home
remember_me:
secret: "%env(GOOGLE_CLIENT_SECRET)%"
lifetime: 604800
always_remember_me: true但现在克莱告诉我我需要换个“警卫”。如果我使用custom_authenticator选项,会出现很多错误,因为我使用的是SocialAuthenticator,正如您在这里看到的那样:https://codeshare.io/Od84jx --如果我从security.yaml中删除google部件--我没有错误,注册和登录工作,但不记得me令牌。
发布于 2022-07-27 13:10:39
我终于成功了,我为那些有同样问题的人分享我的解决方案。
因此,在symfony 5.4到symfony 6.1中,您需要使用OAuth2Authenticator而不是SocialAuthenticator。您可以按照文档编写GoogleAuthenticator:https://github.com/knpuniversity/oauth2-client-bundle#step-1-using-the-new-oauth2authenticator-class
然后,只需将其添加到custom_authenticator文件中的security.yaml部分。例如:
main:
switch_user: true
lazy: true
provider: app_user_provider
custom_authenticator:
- App\Security\LoginAuthenticator
- App\Security\GoogleAuthenticator如果你已经有了控制器,它就能工作了。(https://github.com/knpuniversity/oauth2-client-bundle#step-3-use-the-client-service)
https://stackoverflow.com/questions/73122951
复制相似问题