question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AppAuthGuard - (401) Unauthorized after login

See original GitHub issue

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search for issues before submitting
- [ ] feature request

Versions.

keycloak-angular: 4.0.0 angular: 6.1.10 keycloak: 4.8.1.Final

Repro steps.

Follow example for keycloak-heroes to add AppAuthGuard.ts

The log given by the failure.

No Authorization: Bearer + token in request (401) Unauthorized

Desired functionality.

The documentation says that the Authorization header is added automatically, but it seems to not be the case for me. I am using Http that comes from DI in Angular.js. I know that my Keycloak instance works. I originally had my OIDC going through the server instead of the client. All I have updated is removed the middleware from the server and moved the OIDC flow to the client code. The sign in works as expected, but the request to my API is no longer working.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bdparrishcommented, Jan 9, 2019

Awesome. I was thinking HttpClient was the underlying to Http. Thanks, refactoring to HttpClient worked for everything.

1reaction
mauriciovigolocommented, Jan 9, 2019

Hi @bdparrish,

The Authorization header is added automatically only with HttpClient introduced in Angular v4.3. The reason for this is that the HttpInterceptor only works with HttpClient.

I just tried the keycloak-heroes example and it seems that there is a problem with opendota-api. That is the reason I’m working on the new examples including a simple server demo, using express. This server example will be the backend for all client examples - heroes, events, uma and a ionic.

Just confirm which Http implementation you are using. With Http it won’t work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Login request is always 401 Unauthorized with AuthGuard
Unfortunately, I always receive a Unauthorized response when trying to do a login request. I think the problem comes from my super.
Read more >
How to Quickly Fix the 401 Unauthorized Error (5 Methods)
“401 Unauthorized”; “Access Denied”. These errors occur on websites that require a login in order to access them. In most cases, it means...
Read more >
401 Error: 5 Ways to Troubleshoot and Fix It - Hostinger
The 401 Unauthorized error is triggered by unauthenticated requests made to a WordPress web server. Learn how to identify and fix the issue....
Read more >
401 Unauthorized - HTTP - MDN Web Docs
This status code is sent with an HTTP WWW-Authenticate response header that contains information on how the client can request for the resource ......
Read more >
HTTP 401 Unauthorized Error | What Is and How to Fix?
Do you encounter an HTTP error 401 unauthorized access is denied when you want to login on a website? The 401 Unauthorized Access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found