I'm trying to write a service that accesses the spotify api. Therefore this services needs an authorization bearer token. It should get this from another service, which returns an observable. How can I put these together?
My first attempt looks like this:
getSpotifyData(spotifyId: string): Observable<string> {
let url = "https://api.spotify.com/v1/tracks/" + spotifyId;
this.config.getSpotifyToken().subscribe(bearer => {
return this.http.get<string>(url, {headers: {"Authorization": "Bearer " + bearer}});
});
}
Here the problem is, that this method must return an Observable, wether the config service works or not. This is not the case right now.
Is it possible to combine both observable so that my method can just return a combined observable?