通过oauth服务器通过zool授权请求zool

问题描述 投票:0回答:1

我的应用程序有zuul代理后面的(spring)网关微服务。还有内部(spring)oauth2授权服务器。我想为来自外部的微服务调用实现client_credentials授权类型 - 用于M2M通信。

当我在其application.yml中配置网关client_id和client_secret时,请求来自网关,但是没有请求者检查 - oauth授权网关本身,因此根本没有授权。我可以使用授权代码授权类型,但是它需要Web客户端授权(Web客户端)用户可能没有。

如果我从oauth微服务请求身份验证令牌,我会获得此应用程序的正确令牌。

如何强制网关使用请求者的client_id和client_secret从oauth获取令牌? - 例如我可以通过标题提供它们作为基本授权。或者我可以向网关提供请求者从oauth获得的令牌吗?

问题非常类似于另一个问题:Implementing authentication and authorization using Zuul Proxy, Oauth2 on REST Microservices除了可能没有Web客户端的东西,但外部微服务。

spring spring-security oauth-2.0 netflix-zuul gateway
1个回答
0
投票

我已经回答了问题Implementing authentication and authorization using Zuul Proxy, Oauth2 on REST Microservices

在我的情况下,最重要的是配置zuul代理以将授权标头转发到下游服务。最初我虽然使用zuul过滤器,但解决方案更简单 - 只需为zuul配置敏感标头:

server:
  port: 8080
zuul:
  sensitiveHeaders: Cookie,Set-Cookie # <--- this line
  routes:
    spring-security-oauth-resource:
      path: /spring-security-oauth-resource/**
      url: http://localhost:8081/spring-security-oauth-resource
    oauth:
      path: /oauth/**
      url: http://localhost:8083/spring-security-oauth-server/oauth

使用oauth成功验证客户端/用户后,JWT令牌将由网关转发到下游。当然,对于此网关,必须允许对oauth资源进行未经身份验证的访问,并要求对所有其他资源进行身份验证。

有关这些主题的更多详细信息,请参阅文章https://www.baeldung.com/spring-security-zuul-oauth-jwt

© www.soinside.com 2019 - 2024. All rights reserved.