java - Spring oauth2 sso 示例不起作用

标签 java spring spring-boot oauth-2.0 spring-security-oauth2

我正在尝试重复 official tutorial(Spring Boot and OAuth2) 中描述的操作

我停留在Hosting an Authorization Server部分

我尝试下载所有 sources from github但结果是一样的

我正在尝试启动子项目social-auth-server:

我在那里找到了 2 个首发:

src\main\java\com\example\SocialApplication.java - oauth2 服务器 src\test\java\com\example\ClientApplication.java - oauth2 客户端

引用教程:

Note that the server.context-path is set explicitly, so if you run the app to test it remember the home page is http://localhost:9999/client. Clicking on that link should take you to the auth server and once you you have authenticated with the social provider of your choice you will be redirected back to the client app

1.我已经启动了两个应用程序
2. 在浏览器中输入 localhost:9999/client
3. 由于上一步 - 浏览器将我重定向到 localhost:8080
4. 我点击通过 Facebook 登录
5. 由于上一步 - 浏览器将我重定向到 Facebook 以输入凭据。
6.我输入了正确的凭据
7. 作为上一步的结果 - 浏览器将我重定向到 localhost:8080。即使此页面上没有我的名字。

我希望浏览器会将我重定向到 localhost:9999 并显示消息 Hello Nikolay!

你能帮我完成这个教程吗?

最佳答案

您正在使用教程中定义的 application.yml 。该 Facebook 应用程序是使用 localhost:8080 url 注册的。它在该教程本身中指定。

The configuration refers to a client app registered with Facebook in their developers site, in which you have to supply a registered redirect (home page) for the app. This one is registered to "localhost:8080" so it only works in an app running on that address.

尝试创建您自己的 Facebook 应用程序,并在配置中将重定向 URL 设置为 localhost:9999。在 application.yml 中添加应用程序的配置

OAuth Auth 服务器将始终尝试将 token 重定向到配置的重定向 URL

关于java - Spring oauth2 sso 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49939639/

相关文章:

java - 在 Java FXML 标记文件中运行 Java 代码

java - 应用服务器如何注入(inject)私有(private)字段?

java - 如何确保 Flyway 在我的 bean 之前加载?

java - 如何在 Spring Cloud Config 中定义共享数据源

java - 当类路径包含许多目录时,类路径根是什么意思?

java - 了解 Stack 实现问题陈述

java - Maven 版本 :perform error with assembly plugin (Multi module project)

java - 使用 Spring MessageListener 分组消费消息?

java - 时间戳 Spring 转换

java - JPA:如何处理多个实体