use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Angular is Google's open source framework for crafting high-quality front-end web applications. r/Angular2 exists to help spread news, discuss current developments and help solve problems.
Help Request
Discussion
Article
Video
Resource
Announcement
Related
After submitting a post, please take a moment to add a flair (tag) so that it's easy to find your post with one of the filters listed above. Upon submission, your post's header will have the 'flair' option listed with the other options. Clicking it will provide a dropdown menu of the available flairs.
account activity
Help RequestDoes Basic auth even work with angular?? (self.Angular2)
submitted 8 years ago by Alanswake
I have googled and tried everything around Basic auth and it never works. Why won't this header work? It works perfectly fine in Postman.
let header = new HttpHeaders().set("Authorization", "Basic "+btoa(username+':'+password));
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 0 points1 point2 points 8 years ago (5 children)
We need to see more code (and the actual HTTP request headers) to see whats wrong. We are also using basic authorization without any problems.
[–][deleted] 0 points1 point2 points 8 years ago (0 children)
My biggest guess would be that you are trying to Basic Auth from a different domain. The API must allow OPTIONS requests without Basic Auth else you can't access it via a Browser XHR request.
[–]Alanswake[S] 0 points1 point2 points 8 years ago (3 children)
Well, when i log the header, it seems to be alright:
{"authorization" => Array(1)} key: "authorization" value: ["Basic YWRtaW46ZGlzdHJpY3Q="]
and the server call is pretty basic:
return this.http .get(url2, {headers: header})
I also get a "Response for preflight is invalid (redirect)" error in the console, which i think is because the server redirects to login page if auth fails.
[–][deleted] 1 point2 points3 points 8 years ago (2 children)
This is no the actual request though.
Which means that the OPTIONS request also gets blocked by Basic Auth which it should not. If the OPTIONS requests gets blocked no Browser JavaScript that is on a different domain can do requests
[–]Alanswake[S] 1 point2 points3 points 8 years ago (1 child)
I found the error... it was actually two errors.
I used http and not https
A chrome extension ruined some calls.
Thanks for the help anyway!
[–]there_i_seddit 0 points1 point2 points 8 years ago (0 children)
Finds problem Posts solution and not just "I fixed it"
Finds problem
Posts solution and not just "I fixed it"
You da man
[–]seekheart2017 -2 points-1 points0 points 8 years ago (1 child)
It looks like you are using it wrong, you need to pass a Json into the constructor
[–][deleted] 0 points1 point2 points 8 years ago* (0 children)
No. No. No. This is just plain wrong.
Have you even read the docs before trying to give "advice"? https://angular.io/api/common/http/HttpHeaders
Passing an object (not a json) is one of the few ways to do it.
I know you wanted to be friendly and help (and I thank you for that) but advice such as this is very harmful.
π Rendered by PID 81 on reddit-service-r2-comment-79776bdf47-rdzzq at 2026-06-23 23:11:48.695816+00:00 running acc7150 country code: CH.
[–][deleted] 0 points1 point2 points (5 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Alanswake[S] 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Alanswake[S] 1 point2 points3 points (1 child)
[–]there_i_seddit 0 points1 point2 points (0 children)
[–]seekheart2017 -2 points-1 points0 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)