4

我正在研究微服务架构,但我在这方面面临一些挑战。

首先让我简要介绍一下架构。

  1. 用户登录并获得一个签名令牌,该令牌将用于调用所有 REST API。

  2. 将有很多 API 服务器使用 Spring 安全性保护 API,并根据用户角色进行授权。

  3. 服务必须相互交互以获取/更新信息。

  4. 每个服务都有权通过身份验证服务器验证令牌问题。

问题:-

  1. 如果用户登录并且使用相同的令牌并将其传递给经过验证的每个服务,则一切正常。因此,在传递令牌时,服务不需要相互信任。

  2. 现在,问题是有一些服务需要从服务器本身调用而无需登录。让我们说一个服务器到服务器的调用。服务将如何验证和授权来自其他服务的调用。

我读到了 spring 微服务,但 Zuul 也不是这里的救星,因为每个 API 服务器都嵌入了 spring 安全性,而不仅仅是 API 网关。

一种解决方案可以是每个服务都有自己的具有特定角色的默认用户,用于登录->获取令牌->使用令牌调用其他服务器 api。

您能否在服务器到服务器调用中给我一些指示,其中每个服务器都使用 Spring Security 进行身份验证和授权。

谢谢。

4

2 回答 2

1

In OAuth2, there is a flow dedicated to server-to-server authorization (Client Credentials Grant Flow). The calling service is a regular client for the second (the resource server), so it must get a token and use it.

In a nutshell, the client tells the authorization server who is he (using its client id / app id), the authorization server gives it a token, which can be used to query the resource server.

I have a resource in french here, the sequence diagram is in english and should be helpful. You can find more information about this flow easily.

For the Spring Security specific stuff, see the spring-security-oauth2 doc.

于 2016-06-16T10:57:30.697 回答
1

Ideally, in the Microservices architecture we should not call the other services within a service. We should instead use the Publisher/Subscriber approach for server to server communication.

Even though if you wish to do it, just pass the Auth-Token as a Header used for authenticating the service to the downstream service, where the token will again be authenticated and thus will give response once authenticated.

于 2018-02-20T05:10:21.217 回答