0

We are using zuul as API gateway in spring cloud. Now we want to extract access token from zuul for further implementation.Please provide suggestion how we want to implement. Thank you

Community
  • 1
  • 1
  • You can make zuul do the authentication.Couple of links to get you started https://jmnarloch.wordpress.com/2015/10/21/spring-cloud-eureka-zuul-and-oauth2-scaling-out-authorization-server/ http://presos.dsyer.com/decks/microservice-security.html#slide25 – Grinish Nepal Aug 04 '16 at 17:36
  • Hi Grinish, Thanks for reply, We have achieved authentication, but we want access token for user management in our application. We want to extract access token and store it in redis session for further implementation. Please provide suggetions. Thank you. – Sagar Gaikwad Aug 05 '16 at 10:31
  • 1
    If i understood your problem correctly you must be having some sort of authorization header that you can read in zuul and pass the access token from there to downstream services. To read that and send it downstream you will need to use pre zuul filter. – Grinish Nepal Aug 05 '16 at 19:06
  • Hi Grinish, can you please guide me how to retrieve from authorization header in zuul. – Sagar Gaikwad Aug 08 '16 at 09:20

1 Answers1

1

To read the authorization header you will need to create a filter in ZUUL my thought is you will need a pre filter you can change it based on your need. Here is what you will need.

public class TestFilter extends ZuulFilter {

@Override
public boolean shouldFilter() {

    return true;
}

@Override
public Object run() {

    final RequestContext ctx = RequestContext.getCurrentContext();
    final HttpServletRequest request = ctx.getRequest();
 //Here is the authorization header being read.
    final String xAuth = request.getHeader("Authorization");
 //Use the below method to add anything to the request header to read downstream. if needed.
    ctx.addZuulRequestHeader("abc", "abc"); 

    return null;
}

@Override
public String filterType() {

    return "pre";
}

@Override
public int filterOrder() {

    return 1;
}

}

You will need a @Bean declaration for Filter in the class where you have @EnableZuulProxy

@Bean
public TestFilter testFilter() {
    return new TestFilter();
}

Hope this helps.!!!

Grinish Nepal
  • 3,037
  • 3
  • 30
  • 49