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

Add more support for AuthorizeAttribute #138

Open
Jack-Edwards opened this issue Dec 10, 2024 · 0 comments
Open

Add more support for AuthorizeAttribute #138

Jack-Edwards opened this issue Dec 10, 2024 · 0 comments

Comments

@Jack-Edwards
Copy link

Jack-Edwards commented Dec 10, 2024

Couple of limitations with regards to customizing the AuthorizeAttribute:

  • Cannot provide Roles due to IAPI0002
  • Cannot provide AuthenticationSchemes due to IAPI0002

Regarding the AuthenticationSchemes, I would like to be able to accept Basic authentication in exchange for a JWT. JWT Bearer authentication would be accepted by all other endpoints.

AuthenticationSchemes Example

public sealed partial record GetTokenQuery();

[Handler]
[Tags("Auth")]
[MapGet("/auth/token")]
[Authorize]
public static partial class GetTokenHandler
{
    private static readonly string[] AuthenticationSchemes = ["Basic"];

    internal static void CustomizeEndpoint(IEndpointConventionBuilder endpoint)
        => endpoint.RequireAuthorization(new AuthorizationPolicy(new List<IAuthorizationRequirement>{ new DenyAnonymousAuthorizationRequirement() }, AuthenticationSchemes));
    
    private static ValueTask<Ok<TokenResponse>> HandleAsync(GetTokenQuery query, ClientAuthorizationService clientAuthorizationService, CancellationToken cancellationToken)
    {
        var token = clientAuthorizationService.CreateToken("foo");
        return ValueTask.FromResult(TypedResults.Ok(token));
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant