Security.HmacAuthentication icon indicating copy to clipboard operation
Security.HmacAuthentication copied to clipboard

asp.net core authentication with .Map()

Open empitegayan opened this issue 8 years ago • 5 comments

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<IActionResult> Test([FromBody] ApiIdentityUser model) model gets null but when i remove middleware authentication gets values.. any thought?

empitegayan avatar Sep 04 '17 06:09 empitegayan

It seems your problem is relation with this so question.

ademcaglin avatar Sep 06 '17 06:09 ademcaglin

@ademcaglin thanks .. any idea to support asp.net core 2.0

empitegayan avatar Jan 13 '18 13:01 empitegayan

@empitegayan @ademcaglin I have ported the code over to ASP.NET Core 2.0: https://github.com/markuspalme/Security.HmacAuthentication

markuspalme avatar Feb 04 '18 18:02 markuspalme

@markuspalme, thanks for porting this over to Core 2.0. Unfortunately, much like this port (https://github.com/RredCat/WebApiHMACAuthentication), POST requests fail. Remove the auth and the POST request succeeds. Add it back in, and the request fails.

Interestingly, the auth seems to succeed, and then the request fails. I noticed none of your tests are POST requests. Any insight?

PerryD avatar Feb 22 '19 16:02 PerryD

@PerryD I have opened an issue in my repository. Let me dig deeper and get back to you there.

https://github.com/markuspalme/Security.HmacAuthentication/issues/1

markuspalme avatar Feb 22 '19 16:02 markuspalme