Skip to content

asp.net core authentication with .Map() #1

@empitegayan

Description

@empitegayan

i'm trying to use hmac authentication on specific api controllers which starts with/api/extso i added these configuration on startup class

app.Map("/api/ext", builder =>
            {
                builder.UseHmacAuthentication(new HmacAuthenticationOptions
                {
                    SecretKey = "abc670d15a584f4baf0ba48455d3b155",
                    AppId = "jDEf7bMcJVFnqrPd599aSIbhC0IasxLBpGAJeW3Fzh4=",
                    AutomaticAuthenticate = true
                });
                builder.UseMvc();
            });

but when i send the request i'm getting 404 not found error but when i remove above code it hits the controller action.

and then i came up with this

bool IsApiRequest(HttpContext context) => context.Request.Path.ToString().StartsWith("/api/ext/");
            app.UseWhen(IsApiRequest, builder =>
            {
                builder.UseHmacAuthentication(new HmacAuthenticationOptions
                {
                    SecretKey = "abc670d15a584f4baf0ba48455d3b155",
                    AppId = "jDEf7bMcJVFnqrPd599aSIbhC0IasxLBpGAJeW3Fzh4=",
                    AutomaticAuthenticate = true
                });
            });

seems it works now (validate properly and hit controller action)

then on controller action public async Task Test([FromBody] ApiIdentityUser model) model gets null but when i remove middleware authentication gets values.. any thought?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions