V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aiamjay
V2EX  ›  Java

如何整合 Spring Gateway 和 Spring OAuth2

  •  
  •   aiamjay · 2022-10-19 04:31:40 +08:00 · 1602 次点击
    这是一个创建于 527 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Spring oauth2 采用授权码模式,提供权限验证 Spring gateway 基于 nacos 我的问题是: 我不想把 OAuth2 的 ip 和端口暴露出来,我想统一走 Gateway ,请问如何配置? 绝对有偿,跪求各位能帮帮忙,欢迎联系我 wx wxb_1202

    9 条回复    2022-10-19 19:57:35 +08:00
    xuanbg
        1
    xuanbg  
       2022-10-19 06:36:33 +08:00
    Spring gateway 写个拦截器,在拦截器里面读取 token 并调用 oauth2 验证用户身份和权限。
    guisheng
        2
    guisheng  
       2022-10-19 08:05:25 +08:00 via iPhone
    这个问题配个域名怎么样?
    guisheng
        3
    guisheng  
       2022-10-19 08:11:44 +08:00 via iPhone
    @xuanbg 授权码模式总有一次要到 验证服务登入页面的。根据 code 获取 token 可以这么做。
    xuanbg
        4
    xuanbg  
       2022-10-19 08:33:27 +08:00
    @guisheng 验证不通过,前端跳转 oAuth2 登入页面。这个网关直接返回 301 就行了吧? API 网关又不是 web 服务
    xuanbg
        5
    xuanbg  
       2022-10-19 08:34:46 +08:00
    @xuanbg 应该是返回 401 ,web 服务收到 401 ,返回 301 跳转到登录页面。
    guisheng
        6
    guisheng  
       2022-10-19 08:38:01 +08:00 via iPhone
    @xuanbg 那这个登入页面是不是 认证服务的 IP+端口呢
    xuanbg
        7
    xuanbg  
       2022-10-19 08:41:09 +08:00
    这要看登录页面用的是 oAuth2 服务的还是自己定制的。毕竟归根结底 oAuth2 只负责发放 /验证 token 而已,通过接口也是一样的。
    damai0419
        8
    damai0419  
       2022-10-19 08:45:35 +08:00
    你的 gateway 和 OAuth2 是两个服务还是一个服务呀?
    两个服务的话,gateway 直接转发就行吧,也不需要暴露 OAuth2 ip 和地址。
    totoro52
        9
    totoro52  
       2022-10-19 19:57:35 +08:00
    我为了整合他们两搞了老久,最后还不如写个 filter 来的轻松
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4090 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:21 · PVG 13:21 · LAX 22:21 · JFK 01:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.