Spring boot 如何从使用另一个微服务的微服务传递JWT令牌?

Spring boot 如何从使用另一个微服务的微服务传递JWT令牌?,spring-boot,jwt,microservices,spring-cloud,jwt-auth,Spring Boot,Jwt,Microservices,Spring Cloud,Jwt Auth,我有两个微服务,比如A和B。在这两个微服务的所有REST端点中,我都实现了JWT身份验证。用户必须使用用户名和密码点击端点(“/login”),生成一个令牌,并将其作为RequestHeader传递给两个服务中的所有端点。 比如在microservice A中,我有一个端点(“test1/createSomething”)。在B中,我有另一个端点(“test2/getSomething”)。现在,我可以从服务B调用(“test2/getSomething”),在服务A中使用假客户端调用(“tes

我有两个微服务,比如A和B。在这两个微服务的所有REST端点中,我都实现了JWT身份验证。用户必须使用用户名和密码点击端点(“/login”),生成一个令牌,并将其作为RequestHeader传递给两个服务中的所有端点。 比如在microservice A中,我有一个端点(“test1/createSomething”)。在B中,我有另一个端点(“test2/getSomething”)。现在,我可以从服务B调用(“test2/getSomething”),在服务A中使用假客户端调用(“test1/createSomething”)

但我不知道如何实现这一点,在服务a中生成JWT令牌并将其传递给服务B,以使用其服务


请帮忙。微服务和探索方面的初学者。

您可以尝试的一种方法是使用单独的会话/jwt服务。 该服务的角色和职责是存储/验证和验证具有以下端点的数据

  • create_token():使用给定的输入数据(如用户信息、过期时间等)创建新的JWT令牌
  • 令牌是否有效():检查令牌是否有效
所以你可以有这样一个流程:-


 1. First hit to login-service > login service getting token from jwt-service > returning jwt token to UI/client.
 2. UI/Client passing received jwt token to service-b via headers> which indeed pass jwt token to service-a, where each service independently calls is_token_valid() of jwt-service and process the request only after getting success response. 
为了在spring boot中实现这一点,您可以添加一个拦截器层,在每个控制器类之前调用拦截器层,其中is读取头,提取jwt令牌并从jwt服务验证

你可以看到类似的答案。
另一个参考

您可以尝试的一种方法是使用单独的会话/jwt服务。 该服务的角色和职责是存储/验证和验证具有以下端点的数据

  • create_token():使用给定的输入数据(如用户信息、过期时间等)创建新的JWT令牌
  • 令牌是否有效():检查令牌是否有效
所以你可以有这样一个流程:-


 1. First hit to login-service > login service getting token from jwt-service > returning jwt token to UI/client.
 2. UI/Client passing received jwt token to service-b via headers> which indeed pass jwt token to service-a, where each service independently calls is_token_valid() of jwt-service and process the request only after getting success response. 
为了在spring boot中实现这一点,您可以添加一个拦截器层,在每个控制器类之前调用拦截器层,其中is读取头,提取jwt令牌并从jwt服务验证

你可以看到类似的答案。 另一个参考