Implementing authentication and authorization using Zuul Proxy, Oauth2 on REST Microservices

前端 未结 4 1378
死守一世寂寞
死守一世寂寞 2021-02-03 15:03

I am trying to implement the above architecture in the workflow with Spring Boot.

  • Web client makes a request to Resource Server (Microservices Endpoints)
4条回答
  •  忘掉有多难
    2021-02-03 15:39

    I am not sure whether you were able to resolve this, I can see this is not answered yet, but there is a way you can pass all information from JWT to all downstream microservices. Write your own ZuulAuthenticationFilter, and then create below method

    private void addClaimHeaders(RequestContext context, String token) {
        
        try {
            
            Map claims = jwtTokenVerifier.getAllClaims(token);
            claims.forEach((key, claim) -> {
                
                context.addZuulRequestHeader("x-user-info-"+key, String.valueOf(claim.as(Object.class)));
            });
            
        }catch(Exception ex) {
            
            log.error("Error in setting zuul header : "+ex.getMessage(), ex);
        }
    }
    

    this way, you will get information from JWT in headers in each microservice, headers that starts with "x-user-info-" will have your JWT details

提交回复
热议问题