[英]JHipster: Receive 401 Unauthorized when making API call to microservice
我目前正在使用Jhipster生成以下組件:
其他組件:
另外需要注意的是,自定義前端使用的是Jhipster angular 4代碼,可以在vanilla Jhipster Api Gateway中找到。 這包括customHttpProvider。
目前我能夠使用此設置成功登錄並在UAA上調用API,但是,當我嘗試在產品上調用任何APIS時,我會獲得401 Unauthorized ,例如Post to Product1 / api / zcd 。
Consul中的服務都是可見的和綠色的,Gateway也有UAA和Product1作為注冊和可用路線。
到目前為止,我發現當我對Product進行api調用時,似乎沒有調用AuthInterceptor。 我嘗試手動將jwt令牌附加到方法,這解決了問題,但我不明白為什么customHttpProvider不被用於攔截請求和附加令牌。
如下所示,當我手動插入令牌時,我的ProductService工作正常,但這顯然不是正確的方法。
@Injectable()
export class ProductService {
private options = new Headers();
constructor(private http: Http) {
this.options.append('Authorization', 'Bearer ' + 'token is inserted here');
}
priceProduct(productPriceRequest: productPriceRequest): Observable<IdResponse> {
return this.http.post('Product1/api/zcd', productPriceRequest, { headers: this.options })
.map(response => response.json());
}
}
解決了:
有兩件事給我帶來了問題。 需要注意的是,它們與JHipster沒有直接聯系,而是與Jhipster集成的問題:
問題:
解決方案:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.