How to set Authorization Header ?
See original GitHub issueI am using 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.
});
Note: Before implementing Authorization same code working fine as i don’t need to set authorization header.
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >http post - how to send Authorization header?
Unfornately there is no Authorization header. How should I add it correctly? Whole request sent by my code looks as follow: OPTIONS /oauth/token?grant_type= ......
Read more >Generate an Authorization Header
Generate an Authorization Header · In the command line, type the following command, including the single quotation marks: echo -n '<user_name>:< ...
Read more >Authorizing requests | Postman Learning Center
In the Authorization tab for a request, select OAuth 2.0 from the Type dropdown list. Specify if you want pass the auth details...
Read more >HTTP headers: Authorization header | Web Services Tutorial
Click the below link to download the Java Source code and PPT: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@HNeukermans Thanks for response.
Issue it that is have two signalr client , one is in simple angularjs and other is ionic 2 .
In Simple Angularjs i’m doing following to set the header. (Which is working).
I’m wondering if there is way to send headers just like above . If i go for query string option that is what you suggested then i have to change a lot of code on server side as well as on simple angularjs signalr client .
Is there any other way ?
We created a custom service where the SignalR and OAuthService are injected. Below is a basic example where the ISignalRConnection is provided through an Observable. This way, if the connection is interrupted and re-establised, you are able to automatically resubscribe to the new connection.
And to listen for a message, inject this SignalrService and subscribe to the connection Observable: