I have a Asp.NET Core MVC application that Controller always gets invoked from the View. I am now extending the application by exposing new API endpoint which can be called from outside like Postman.
I am facing an issue of getting 405 - Method Not Allowed when I put [Authorize] attribute on top of my controller. without this attribute I can hit the endpoint and the Model gets bounded with the values I provided from postman as expected.
Below is how my controller looks like:
[Authorize]
[Route("api/v1/auth")]
public class ApiAuthController : Controller
{
[HttpPost("changePassword")]
public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordModel model)
{
return null;
}
}
It might worth to mention that, this application is the same application that provides the Bearer token which I later use in the postman.
In my Startup.cs file I have the following settings related to IdentityServer and Authorization:
services
.AddIdentityServer(options =>
{
options.Events.RaiseErrorEvents = true;
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
})
.AddSigningCredential(cert)
.AddAspNetIdentity<IdentityUser>()
.AddAuthentication()

