gpt4 book ai didi

java - Spring社交登录和重定向并返回值

转载 作者:行者123 更新时间:2023-11-29 08:54:03 28 4
gpt4 key购买 nike

我正在测试 Spring Social Showcase 并编写了一个类似的应用程序。虽然 Spring Social Showcase 是一个使用 Spring MVC 编写的简单 HTML 应用程序,但我的应用程序使用的是 angularjs 和 AJAX。 Twitter 或 Facebook 接受访问 token 后重定向出现问题。

在我的流程中,首先我更改了 ProviderSignInController 的设置:

providerSignInController.setSignUpUrl("/register/social"); <-- redirect into my controller

然后是我的 Controller :

@RequestMapping(value="/social" ,method=RequestMethod.GET)
public ModelAndView social(WebRequest request, ){
LOG.info("Register new user using social info");
Connection<?> connection = ProviderSignInUtils.getConnection(request);

if(connection != null){
LOG.info("User has been authorize from " + connection.getKey().getProviderId());
LOG.info("Connection class: " + connection.getClass());
model.addAttribute("socialUser",RegisterUserDto.fromSocialProfile(connection.fetchUserProfile()) );
}else{

}

return new ModelAndView("redirect:http://localhost:8080/turnigo-core-web/#/register");
}

此 Controller 只是将我重定向回带有注册表单的网站,但我没有从社交提供商那里获得任何用户个人资料数据。简单的重定向工作正常,但对我的应用程序来说还不够。 :/

我不知道如何解决它,所以这是我的问题:

  1. 是否可以在另一个网页中打开社交身份验证网站,然后将其关闭并返回到具有用户配置文件数据的上一个页面?

  2. 是否有任何使用 Spring Social 登录的 AJAX 应用程序示例?

最佳答案

我建议使用 SocialAuthenticationFilter 而不是 ProviderSignInController。SocialAuthenticationFilter 为 spring security 社交登录提供了完整的 Controller 。社交用户成功登录后,您希望重定向到主页,否则重定向到错误页面。

我有一个简单的 spring 社交登录示例,它使用 SocialAuthenticationFilter 进行身份验证并与社交提供商保持联系。希望对您有所帮助。

Here是如何使用 spring 框架实现社交登录功能的示例。 Blog这个应用程序的精确解释。

关于java - Spring社交登录和重定向并返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21269990/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com