I'm using Angular 6 and RxJs 6.5.2. I cannot for the life of me figure out the syntax for chaining observables to add an access token to HTTP requests and return the type needed to satisfy the intercept method. I've tried all permutations of subscribe, pipe, map...
private getApiToken(): Observable<any> {
// TODO load from configuration
return this.httpClient.post("https://localhost:1234/connect/token",
{
grant_type: "client_credentials",
client_id: "MyClient",
client_secret: "MySecret",
scope: "ApiScope"
});
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// how do I call getApiToken here?
return next.handle(req);
}
Note that if I ever get this working I will of course cache the token.