Getting “error”: “unsupported_grant_type” when trying to get a JWT by calling an OWIN OAuth secured Web Api via Postman

The response is a bit late – but in case anyone has the issue in the future… From the screenshot above – it seems that you are adding the url data (username, password, grant_type) to the header and not to the body element. Clicking on the body tab, and then select “x-www-form-urlencoded” radio button, there … Read more

Can’t find Request.GetOwinContext

The GetOwinContext extension method is in the System.Web.Http.Owin dll which needs to be downloaded as a nuget package (The nuget package name is Microsoft.AspNet.WebApi.Owin) Install-Package Microsoft.AspNet.WebApi.Owin See msdn here: http://msdn.microsoft.com/en-us/library/system.net.http.owinhttprequestmessageextensions.getowincontext(v=vs.118).aspx Nuget package here: https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Owin However, the method is still part of the System.Net.Http namespace, so the using definitions you have should be fine. EDIT Okay, … Read more

ASP.NET_SessionId + OWIN Cookies do not send to browser

I have encountered the same problem and traced the cause to OWIN ASP.NET hosting implementation. I would say it’s a bug. Some background My findings are based on these assembly versions: Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 Microsoft.Owin.Host.SystemWeb, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a OWIN uses it’s own abstraction to work with response Cookies (Microsoft.Owin.ResponseCookieCollection). This … Read more

Unauthorised webapi call returning login page rather than 401

Brock Allen has a nice blog post on how to return 401 for ajax calls when using Cookie authentication and OWIN. http://brockallen.com/2013/10/27/using-cookie-authentication-middleware-with-web-api-and-401-response-codes/ Put this in ConfigureAuth method in the Startup.Auth.cs file: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”), Provider = new CookieAuthenticationProvider { OnApplyRedirect = ctx => { if (!IsAjaxRequest(ctx.Request)) { ctx.Response.Redirect(ctx.RedirectUri); … Read more

Adding ASP.NET MVC5 Identity Authentication to an existing project

Configuring Identity to your existing project is not hard thing. You must install some NuGet package and do some small configuration. First install these NuGet packages with Package Manager Console: PM> Install-Package Microsoft.AspNet.Identity.Owin PM> Install-Package Microsoft.AspNet.Identity.EntityFramework PM> Install-Package Microsoft.Owin.Host.SystemWeb Add a user class and with IdentityUser inheritance: public class AppUser : IdentityUser { //add your … Read more

Do I need a Global.asax.cs file at all if I’m using an OWIN Startup.cs class and move all configuration there?

Startup.Configuration gets called slightly later than Application_Start, but I don’t think the difference will matter much in most cases. I believe the major reasons we kept the other code in Global.asax are: Consistency with previous versions of MVC. (That’s where everybody currently expects to find this code.) Ability to add other event handlers. In Global.asax, … Read more

When should I use OWIN Katana?

In asp.net WebApi v2, the OWIN pipeline becomes the default. It is eventually going to be the standard pipeline under any asp.net project. I cannot put it better than what is written here : http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana The section “The Open Web Interface for .NET (OWIN)” explains perfectly the goals of OWIN. Without OWIN, the asp.net bits … Read more

How to explain Katana and OWIN in simple words and uses?

Regarding the comment above, OWIN is not a framework. OWIN is a specification on how web servers and web applications should be built in order to decouple them and allow movement of ASP.NET applications to environments which were not supported before. Prior to OWIN, when building ASP.NET application, you were inherently bound to IIS due … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)