gateway 集成 oauth2 提示Invalid credentials
来源:11-5 微服务认证方案03-“网关认证授权,内部裸奔”方案
破地瓜
2020-05-14
gateway 集成oauth2 做单点登陆有案例吗 或者思路吗
网关授权,内部裸奔方案
参考文档:
https://docs.spring.io/spring-security/site/docs/5.4.0-M1/reference/html5/#webflux-oauth2
参考用例;
https://github.com/spring-projects/spring-security/tree/5.4.0-M1/samples/boot/oauth2login-webflux
使用gitee 添加了第三方应用;
认证授权都通过了
过程:
- 访问http://localhost:8080
- 显示gitee登陆界面
- 登陆成功后出现授权页面,点击确定后 出现以下错误页面.最下面是日志
项目已上传至github 地址如下:
https://github.com/jiabiaoli/webflux-oauth2.git
页面报错如下图
以下是debug 日志;
2020-05-14 12:31:26.899 DEBUG 11514 --- [ main] o.s.c.e.PropertySourcesPropertyResolver : Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties' with value of type String
2020-05-14 12:31:27.036 INFO 11514 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2020-05-14 12:31:27.040 INFO 11514 --- [ main] c.s.itsm.oauth2.Oauth2DemoApplication : Started Oauth2DemoApplication in 1.704 seconds (JVM running for 2.356)
2020-05-14 12:31:27.506 DEBUG 11514 --- [1)-192.168.1.15] o.s.c.e.PropertySourcesPropertyResolver : Found key 'local.server.port' in PropertySource 'server.ports' with value of type Integer
2020-05-14 12:31:36.681 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-1] HTTP GET "/"
2020-05-14 12:31:36.739 DEBUG 11514 --- [oundedElastic-1] o.s.w.s.s.DefaultWebSessionManager : Created new WebSession.
2020-05-14 12:31:36.796 DEBUG 11514 --- [oundedElastic-1] .s.u.m.MediaTypeServerWebExchangeMatcher : httpRequestMediaTypes=[text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
2020-05-14 12:31:36.796 DEBUG 11514 --- [oundedElastic-1] .s.u.m.MediaTypeServerWebExchangeMatcher : Processing text/html
2020-05-14 12:31:36.796 DEBUG 11514 --- [oundedElastic-1] .s.u.m.MediaTypeServerWebExchangeMatcher : text/html .isCompatibleWith text/html = true
2020-05-14 12:31:36.797 DEBUG 11514 --- [oundedElastic-1] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-1] Completed 302 FOUND
2020-05-14 12:31:36.815 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-2] HTTP GET "/oauth2/authorization/demo"
2020-05-14 12:31:36.833 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-2] Completed 302 FOUND
2020-05-14 12:31:36.887 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-3] HTTP GET "/"
2020-05-14 12:31:36.892 DEBUG 11514 --- [ctor-http-nio-2] .s.u.m.MediaTypeServerWebExchangeMatcher : httpRequestMediaTypes=[text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
2020-05-14 12:31:36.892 DEBUG 11514 --- [ctor-http-nio-2] .s.u.m.MediaTypeServerWebExchangeMatcher : Processing text/html
2020-05-14 12:31:36.892 DEBUG 11514 --- [ctor-http-nio-2] .s.u.m.MediaTypeServerWebExchangeMatcher : text/html .isCompatibleWith text/html = true
2020-05-14 12:31:36.893 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-3] Completed 302 FOUND
2020-05-14 12:31:36.895 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-4] HTTP GET "/oauth2/authorization/demo"
2020-05-14 12:31:36.896 DEBUG 11514 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter : [d9bca978-4] Completed 302 FOUND
2020-05-14 12:32:19.784 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-5] HTTP GET "/"
2020-05-14 12:32:19.786 DEBUG 11514 --- [oundedElastic-1] o.s.w.s.s.DefaultWebSessionManager : Created new WebSession.
2020-05-14 12:32:19.787 DEBUG 11514 --- [oundedElastic-1] .s.u.m.MediaTypeServerWebExchangeMatcher : httpRequestMediaTypes=[text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
2020-05-14 12:32:19.788 DEBUG 11514 --- [oundedElastic-1] .s.u.m.MediaTypeServerWebExchangeMatcher : Processing text/html
2020-05-14 12:32:19.788 DEBUG 11514 --- [oundedElastic-1] .s.u.m.MediaTypeServerWebExchangeMatcher : text/html .isCompatibleWith text/html = true
2020-05-14 12:32:19.788 DEBUG 11514 --- [oundedElastic-1] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-5] Completed 302 FOUND
2020-05-14 12:32:19.792 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-6] HTTP GET "/oauth2/authorization/demo"
2020-05-14 12:32:19.794 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-6] Completed 302 FOUND
2020-05-14 12:32:20.350 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-7] HTTP GET "/"
2020-05-14 12:32:20.353 DEBUG 11514 --- [ctor-http-nio-3] .s.u.m.MediaTypeServerWebExchangeMatcher : httpRequestMediaTypes=[text/html, application/xhtml+xml, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8]
2020-05-14 12:32:20.353 DEBUG 11514 --- [ctor-http-nio-3] .s.u.m.MediaTypeServerWebExchangeMatcher : Processing text/html
2020-05-14 12:32:20.353 DEBUG 11514 --- [ctor-http-nio-3] .s.u.m.MediaTypeServerWebExchangeMatcher : text/html .isCompatibleWith text/html = true
2020-05-14 12:32:20.353 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-7] Completed 302 FOUND
2020-05-14 12:32:20.357 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-8] HTTP GET "/oauth2/authorization/demo"
2020-05-14 12:32:20.358 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-8] Completed 302 FOUND
2020-05-14 12:32:23.362 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-9] HTTP GET "/login/oauth2/code/demo?code=f9ec3f3a22179fa2954f075339d5347a8f4c3dd3286da50af7557647f169b75b&state=PgeF-SxuvTI4aSqQGi90sT5h0WM5zx7xsGDADa8enI8%3D"
2020-05-14 12:32:23.400 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.r.f.client.ExchangeFunctions : [5789ca66] HTTP POST https://gitee.com/oauth/token
2020-05-14 12:32:23.968 DEBUG 11514 --- [ctor-http-nio-5] o.s.http.codec.FormHttpMessageWriter : [5789ca66] Writing form fields [grant_type, code, redirect_uri] (content masked)
2020-05-14 12:32:24.133 DEBUG 11514 --- [ctor-http-nio-5] o.s.w.r.f.client.ExchangeFunctions : [5789ca66] Response 200 OK
2020-05-14 12:32:24.178 DEBUG 11514 --- [ctor-http-nio-5] o.s.http.codec.json.Jackson2JsonDecoder : [5789ca66] Decoded [{access_token=0b44b5e9c6cab1a619d38e59bf33007d, token_type=bearer, expires_in=86400, refresh_token=e (truncated)...]
2020-05-14 12:32:24.189 DEBUG 11514 --- [ctor-http-nio-5] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-9] Completed 302 FOUND
2020-05-14 12:32:24.192 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-10] HTTP GET "/login?error"
2020-05-14 12:32:24.200 DEBUG 11514 --- [ctor-http-nio-3] o.s.w.s.adapter.HttpWebHandlerAdapter : [ca5957ee-10] Completed 200 OK
写回答
2回答
-
大目
2020-05-14
不太清楚哦 不好意思啦
00 -
破地瓜
提问者
2020-05-14
应该不是客户端代码的问题 将gitee 换成github 就可以 换成gitlab 后反复出现授权页面
00
相似问题
gateway如果转发到页面
回答 1
gateway问题
回答 1