Using a wwwroot folder (ASP.NET Core style) in ASP.NET 4.5 project

I believe I have a working method for doing this now. Took a bit of googling and experimentation, but in the end I came up with the following process: Create a new ASP.NET 4.5 project in VS2015, selecting the Empty Template Add OWIN references through nuget (Install-Package Microsoft.Owin.Host.SystemWeb and Microsoft.Owin.StaticFiles) Add a startup file similar … Read more

Get IPrincipal from OAuth Bearer Token in OWIN

I found a part of the solution in this blog post: http://leastprivilege.com/2013/10/31/retrieving-bearer-tokens-from-alternative-locations-in-katanaowin/ So I created my own Provider as follows: public class QueryStringOAuthBearerProvider : OAuthBearerAuthenticationProvider { public override Task RequestToken(OAuthRequestTokenContext context) { var value = context.Request.Query.Get(“access_token”); if (!string.IsNullOrEmpty(value)) { context.Token = value; } return Task.FromResult<object>(null); } } Then I needed to add it to my … Read more

ASP.NET (OWIN) Identity: How to get UserID from a Web API controller?

You should be able to get user id on both MVC controller and web api controller by same extension method in identity 1.0 RTW package. Here is the extensions from identity package: namespace Microsoft.AspNet.Identity { public static class IdentityExtensions { public static string FindFirstValue(this ClaimsIdentity identity, string claimType); public static string GetUserId(this IIdentity identity); public … Read more

How do you login/authenticate a user with Asp.Net MVC5 RTM bits using AspNet.Identity?

So here’s what login will basically look like in RTM (code copied from the ASPNET Identity sample code): // // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); return RedirectToLocal(returnUrl); } else { … Read more

Context.User.Identity.Name is null with SignalR 2.X.X. How to fix it?

I found the final solution, this is the code of my OWIN startup class: public void Configuration(IAppBuilder app) { app.MapSignalR(); // Enable the application to use a cookie to store information for the signed i user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Home/Index”) }); // Use a cookie to temporarily store information … Read more

How to access Facebook private information by using ASP.NET Identity (OWIN)?

Create a new Microsoft.Owin.Security.Facebook.AuthenticationOptions object in Startup.ConfigureAuth (StartupAuth.cs), passing it the FacebookAppId, FacebookAppSecret, and a new AuthenticationProvider. You will use a lambda expression to pass the OnAuthenticated method some code to add Claims to the identity which contain the values you extract from context.Identity. This will include access_token by default. You must add email to … Read more

OWIN’s GetExternalLoginInfoAsync Always Returns null

To get OWIN Google login to work properly on a standard Visual Studio 2013, ASP.Net MVC5 site, I had to: Setup a Google OpenId account at https://console.developers.google.com/project Set the callback URL there to blah/signin-google. Important notes on things you don’t need to do: You don’t need to use HTTPS for Google to redirect back; you … Read more

Self hosted OWIN and urlacl

so it turns out you need to pass in a url into StartOptions in the same format as the urlacl. Changing the start options to the code below fixed the problem. now the app is accessible across the network. var options = new StartOptions(“http://*:8989”) { ServerFactory = “Microsoft.Owin.Host.HttpListener” };