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.

Angular interceptor should support APIs with optional authentication

See original GitHub issue

Core Library

MSAL.js v2 (@azure/msal-browser)

Wrapper Library

MSAL Angular (@azure/msal-angular)

Description

There should be a way in the angular interceptor to specify an API where authentication is optional (i.e. it should send the access token if it has a valid one, or if it can silent acquire one, but omit it otherwise). This is useful for APIs that do not strictly require authentication, but provide additional functionality if authenticated. It might return only public data to an anonymous user, but include personalized data for a signed in user, or signed in users may have less restrictive rate limiting, etc.

Furthermore, the need for authentication can vary for the same URL by http method, and right now there is no way to support that without a full.

For the first scenario, this feels like it should be a relatively easy feature to add, since it is simply skipping the this.acquireTokenInteractively calls. Even for the second scenario, sending the access token (when available) when not actually required is usually harmless, so both scenarios could be supported in this same manner.

The only tricky part seems to me to be the ability to specify this option. I would simply update the ProtectedResourceScopes type to make httpMethod optional (with semantics that not supplied means any method), and add a new boolean to trigger the new behavior. The reason I would put it on the scopes level rather than the resource level is because that is where the httpMethod is specified, and this should allow (but not require) distinguishing by method.

Thoughts?

Source

External (Customer)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hansmaadcommented, Sep 23, 2022

It would be great if the interceptor would be more open for extension in general. Every little attempt for customization usually means that we have to copy the whole thing and do changes instead of extending it.

1reaction
andreaslarssencommented, Sep 19, 2022

My issue (#4932) was closed in favor of this one. @bmahall answered that one with I am currently looking into this , thanks for your patience!, but this issue hasn’t moved in almost a year.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP Interceptor to Set Auth Header for API Requests if User ...
This is a quick example of how to automatically set the HTTP Authorization header for requests sent from an Angular app to an...
Read more >
Angular Authentication: Using the Http Client and ... - Medium
Let's take a look at how to use Angular's HttpInterceptor interface to ... Any authentication service should have a few basic methods for ......
Read more >
Angular Interceptors to Manage HTTP Requests
Learn how to use Angular interceptors to manage HTTP requests including JWT authorization , caching and logging.
Read more >
Guide on How to Use Interceptor in Angular - KnowledgeHut
Angular interceptors manipulate the headers as they provide features such as authentication and authorization. The angular HTTP interceptors are ...
Read more >
Making API call bypassing Interceptor if one is configured in ...
Hi All, if you have worked on some Angular project and used backend communication with API in which want to add some auth...
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