I am using library ng2-signalr
in ionic 2. Issue is that i don't know how to set authorization header. I have search but didn't find any example.
My code for connecting to server hub.
let options: IConnectionOptions = { qs:{userId:1}, url: "http://192.168.0.211:44337"};
console.log("Stage 1");
//Header for 'this.singalR.connect'
this.signalR.connect(options)
.then((connection) => {
console.log("Client Id: " + connection.id);
}, (err) => {
console.log("SignalR Error: " + JSON.stringify(err));
});
How to set below header ?
var headers = new Headers({
'Content-Type': "application/json",
"Authorization": 'Bearer ' + accessToken //accessToken contain bearer value.
});
Library: ng2-signalr
Update 1
Here on link Query String Solution. A workaround is mention to pass authorization token
in qs
and handle accordingly. But i want to set in header so this solution does not suit me . One more reason as i have one another client(Simple angularjs signalr) which is working fine when i set header just like below.
$.signalR.ajaxDefaults.headers = { Authorization: //here set header};
Note: Before implementing Authorization same code working fine as i don't need to set authorization header.
It is currently (v2.0.4) not implemented in ng2-signalr.
As a workaround, you can try:
declare var $: any;
$.signalR.ajaxDefaults.headers = new Headers({
'Content-Type': "application/json",
"Authorization": 'Bearer ' + accessToken //accessToken contain bearer value.
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With