【发布时间】:2019-05-24 22:54:52
【问题描述】:
在用户进行基本 Facebook 身份验证后,我无法将用户重定向到上一页。相反,我被重定向到主页。我正在遵循https://spring.io/guides/tutorials/spring-boot-oauth2/中提到的示例
这是我的结构:
社交控制器:
@RestController
public class SocialController {
@GetMapping("/user")
public Principal user(Principal principal) {
return principal;
}
}
test.html:
<div class="container unauthenticated">
With Facebook: <a href="login">click here</a>
</div>
<div class="container authenticated" style="display:none">
Logged in as: <span id="user"></span>
</div>
<script>
$.get("/user", function(data) {
console.log("Inside users: " + data);
$("#user").html(data.userAuthentication.details.name);
$(".unauthenticated").hide()
$(".authenticated").show()
});
</script>
主要方法:
@SpringBootApplication
@EnableOAuth2Sso
public class IvanstanevPortfolioApplication extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/css/**", "/js/**", "/img/**", "/audio/**" , "/" ,"/index","/contacts","/about_me","/test")
.permitAll()
.anyRequest()
.authenticated();
}
public static void main(String[] args) {
SpringApplication.run(IvanstanevPortfolioApplication.class, args);
}
}
基本上我想从 Facebook 检索用户名并留在他所在的页面(test.html)。相反,我被重定向到主页。花了一整天的时间,找不到解决方案。 :\
【问题讨论】:
-
你试过baeldung.com/spring-security-5-oauth2-login吗? Spring 5 带有自动配置。
-
不,但我现在就读。谢谢。
-
嘿@reflexdemon 我阅读了指南,但我不明白如何在 HTML 上显示用户名。还有什么意义:5.3。自定义授权端点和 5.4。自定义令牌端点。
标签: spring facebook spring-boot oauth-2.0