Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to prevent access tokens being added on particular addresses? #18344

Closed
taylorchasewhite opened this issue May 16, 2020 — with docs.microsoft.com · 2 comments
Closed
Labels
Blazor doc-provided Source - Docs.ms Docs Customer feedback via GitHub Issue

Comments

Copy link

BaseAddressAuthorizationMessageHandler looks like it requires AccessTokens on any address that is within the base address.

Forgive me if this is described within and I missed it, but I am looking for how best to support certain server API routes being accessed without being logged in. How is this done?


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@dotnet-bot dotnet-bot added ⌚ Not Triaged Blazor Source - Docs.ms Docs Customer feedback via GitHub Issue labels May 16, 2020
@guardrex
Copy link
Collaborator

support certain server API routes being accessed without being logged in

Configure a named HttpClient for it ...

https://docs.microsoft.com/en-us/aspnet/core/security/blazor/webassembly/additional-scenarios?view=aspnetcore-3.1#unauthenticated-or-unauthorized-web-api-requests-in-an-app-with-a-secure-default-client

@yv989c
Copy link

yv989c commented May 25, 2020

@taylorchasewhite You could also write your own AuthorizationMessageHandler, and be explicit on the urls that require authorization.

public sealed class CustomAuthorizationMessageHandler : AuthorizationMessageHandler
{
    public CustomAuthorizationMessageHandler(
        IAccessTokenProvider provider,
        NavigationManager navigation
        )
        : base(provider, navigation)
    {
        var authorizationRequiredUrls = new[]
        {
            getAbsoluteUrl("api/Product/"),
            getAbsoluteUrl("api/Account/")
        };

        ConfigureHandler(authorizationRequiredUrls);

        string getAbsoluteUrl(string relativeUrl)
        {
            return $"{navigation.BaseUri}{relativeUrl}";
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blazor doc-provided Source - Docs.ms Docs Customer feedback via GitHub Issue
Projects
None yet
Development

No branches or pull requests

4 participants