Search code examples
asp.net-coreserverjwtnavigationblazor

Blazor InteractiveServer navigate to external link whilst JWT added to the request headers?


I have a Blazor Server app. I added a link to the navigation menu targetting an external address. Is there any way to add a JWT Bearer token to the header to this request?

I appreciate any advice

I searched the usual sources, but i'm out of ideas.


Solution

  • Any navigation/link/redirect is a Browser behavior. Basically, you are trying to modify browser headers via codes. This is not possible for the current tab.

    I think you may need to re-consider the architecture. Bearer token is designed for apis which is used for "ajax" or "httpclient" calls. There shouldn't be a scenario that you need browser to make http bearer call because an api usually give you back some json response which is not meant to be rendered in a browser.

    If you really need a browser call via codes, the only solution is to use selenium webdriver to have a full control of browser behaviour. But this way have to open another new browser instance for this link.