0
我們在春季雲中使用zuul作爲API網關。現在我們要從zuul中提取訪問令牌以供進一步實現。請提供建議我們如何實現。謝謝從Spring雲zuul API網關獲取AccessToken
我們在春季雲中使用zuul作爲API網關。現在我們要從zuul中提取訪問令牌以供進一步實現。請提供建議我們如何實現。謝謝從Spring雲zuul API網關獲取AccessToken
要閱讀授權標題,您需要在ZUUL中創建一個過濾器,我認爲您需要一個預過濾器,您可以根據需要更改它。這是你需要的。
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;
}
}
您將需要一個@Bean
聲明過濾器類中,你必須@EnableZuulProxy
@Bean
public TestFilter testFilter() {
return new TestFilter();
}
希望這有助於。!
你可以讓zuul做認證。一些鏈接讓你開始https://jmnarloch.wordpress.com/2015/10/21/spring-cloud-eureka-zuul-and-oauth2-scaling-out-授權服務器/ http://presos.dsyer.com/decks/microservice-security.html#slide25 –
嗨Grinish,感謝您的回覆,我們已經實現了身份驗證,但我們希望在我們的應用程序中爲用戶管理提供訪問令牌。我們希望提取訪問令牌並將其存儲在redis會話中以供進一步實施。請提供建議。謝謝。 –
如果我正確理解您的問題,您必須擁有某種您可以在zuul中讀取的授權標頭,並將訪問令牌從那裏傳遞給下游服務。要讀取它並將其發送到下游,您將需要使用pre zuul過濾器。 –