I am trying to implement HMAC authentication using the code given here: http://bitoftech.net/2014/12/15/secure-asp-net-web-api-using-api-key-authentication-hmac-authentication/ .
I have included this code in my ASP.NET web form application. I created a folder called "HMACAPI" and added controllers and filters to it. I also installed all the necessary Nuget packages. This is how I implement my maintenance methods:
[HMACAuthentication] [RoutePrefix("api/forms")] public class FormsController : ApiController { [Route("")] public IHttpActionResult Get() { ClaimsPrincipal principal = Request.GetRequestContext().Principal as ClaimsPrincipal; var Name = ClaimsPrincipal.Current.Identity.Name; return Ok("test"); } [Route("")] public IHttpActionResult Post(string order) { return Ok(order); } }
This is my route configuration for the API:
GlobalConfiguration.Configure(APIWebFormsProject.API.WebApiConfig.Register);
But when I use client.PostAsJsonAsync() , it shows a Method Not Allowed error. I tried different questions, but none of their answers help.
What I tried:
I am using the URL http: // localhost: 56697 / api / forms / to access the API. But I also tried " http: // localhost: 56697 / api / forms " and " http: // localhost: 56697 / api / forms / test ".
UPDATE
As Obsidian Phoenix suggested, I was able to run it without the [HMACAuthentication] attribute. But I want to implement this using HMAC authentication. So what could be the reasons for this?
Aishwarya shiva
source share