spring-boot - 使用身份验证服务器作为尤里卡客户端从资源服务器访问身份验证服务器时出错
问题描述
嗨,我在 springboot 中有一个实现的 oauth2 服务。Auth-server 和资源服务器启用了 eureka 客户端,它们也已成功注册到 eureka 服务器。资源服务器中 auth-server 的 URI 是这样配置的
security:
oauth2:
resource:
token-info-uri: http://auth-server/oauth/check_token
现在auth-server
在上面的 URI 中是 authserver 的应用程序名称。我期望资源服务器token-info-uri
在从 eureka 服务器解析 url 后应该联系 auth 服务器。但是通过这个设置我得到了一个错误nested exception is java.net.UnknownHostException: auth-server
我将我的配置修改为此
security:
oauth2:
resource:
prefer-token-info: false
service-id: auth-server
token-info-uri: http://${security.oauth2.resource.service-id}/oauth/check_token
loadBalanced: true
但我得到了回应
{
"error": "invalid_token",
"error_description": "e2f95093-085c-4b59-90a5-c89fb5d1eccb"
}
当我调试时,我有这个日志
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.048 INFO 1 --- [nio-6001-exec-2] o.s.web.servlet.DispatcherServlet : Completed initialization in 21 ms
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.086 DEBUG 1 --- [nio-6001-exec-2] o.s.b.a.s.o.r.UserInfoTokenServices : Getting user info from: null
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.109 DEBUG 1 --- [nio-6001-exec-2] org.springframework.web.HttpLogging : HTTP GET
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.117 DEBUG 1 --- [nio-6001-exec-2] org.springframework.web.HttpLogging : Accept=[application/json, application/*+json]
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.119 WARN 1 --- [nio-6001-exec-2] o.s.b.a.s.o.r.UserInfoTokenServices : Could not fetch user details: class java.lang.IllegalStateException, Request URI does not contain a valid hostname:
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.120 DEBUG 1 --- [nio-6001-exec-2] o.s.b.a.s.o.r.UserInfoTokenServices : userinfo returned error: Could not fetch user details
asset-mgmt-v1.1_1 | 2019-11-16 17:52:08.127 DEBUG 1 --- [nio-6001-exec-2] o.s.b.a.audit.listener.AuditListener : AuditEvent [timestamp=2019-11-16T17:52:08.125Z, principal=access-token, type=AUTHENTICATION_FAILURE, data={type=org.springframework.security.authentication.BadCredentialsException, message=e2f95093-085c-4b59-90a5-c89fb5d1eccb}]
基本上 URI 被拾起就是我所看到的
解决方案
you cannot use just name in property files. it should be
security:
oauth2:
resource:
service-id: {Service ID as at eureka server registered}
token-info-uri: http://${security.oauth2.resource.service-id}/oauth/check_token
loadBalanced=true
prefer-token-info=false
P.S I just typed by hand. make sure keep proper spaces
推荐阅读
- jquery - 单击当前选项卡后不显示弹出
- python - flask+uwsgi+nginx+centos 导入模块numpy报错
- node.js - FFMPEG 在 AWS lambda 函数中不起作用
- .htaccess - .htaccess 在文件夹中,使文件夹本身消失
- java - Spring Boot @Autowired MessageSource 在一个类中有效,而在另一个类中无效
- php - 为什么可以覆盖在父类中使用的特征中定义的属性的初始值?
- c# - 从 AJAX 帖子调用时,FileContentResult 不生成文件
- php - 我可以在单行中编写多个 RewriteCond 选项吗?
- java-8 - finally 块等效于 CompletableFuture 中的异常处理
- macos - 我不能使用“点击”在 android studio 中添加快捷方式?