I have developed a feature that communicates with an external API endpoint. I have utilized their authentication endpoint to generate a bearer token which I will utilize in subsequent API requests.
Considering this is a third-party API, the URLs and headers for my destination are constructed via a proxy.
Now that I have obtained the access_token, how can I include this token in the authorization header?
https://i.sstatic.net/Dmrzg.png
Component
showOAuth() {
this.zebraService.getOAuth()
.subscribe((data: any) => {
console.log('Zebra Response: ', data);
console.log(data.body);
this.OAuth = data.body;
this.access_token = this.OAuth.access_token;
console.log(this.access_token);
});
}
Proxy
"/zebraAccessApi": {
"target": "https://api.com",
"secure": true,
"changeOrigin": true,
"pathRewrite": {
"^/zebraAccessApi": ""
},
"headers": {
"client_id": "",
"client_secret": ""
}
},
"/zebraSetAppLed": {
"target": "https://api.com/setAppLed",
"secure": true,
"changeOrigin": true,
"pathRewrite": {
"^/zebraSetAppLed": ""
},
"headers": {
"Content-Type": "application/json",
"Authorization": ""
}
}
Service
zebraOAuthUrl = '/zebraAccessApi';
zebraSetAppLedUrl = '/zebraSetAppLed';
public getOAuth() {
let options = {
observe: 'response' as 'body',
response: 'json'
};
return this.http.get(this.zebraOAuthUrl, options);
}