owin

OWIN multi-app bearer token authentication

有些话、适合烂在心里 提交于 2019-12-04 02:56:58
I want to make a modification to the default single page application template for ASP.NET in VS 2013, which currently uses bearer token authentication. The sample uses app.UseOAuthBearerTokens to create both the token server and the middleware to validate tokens for requests in the same app. What I'd like to do is leave that in place, but add a second application (bound in IIS to the same domain, different path - e.g. /auth/* for the authentication server, and /app1/* for the app). For the second app, I want it to accept tokens issued by the authentication server in the first app. How could

Is there a way to convert OwinRequest to HttpRequestBase?

China☆狼群 提交于 2019-12-04 02:44:05
I'm writing a piece of Owin Middleware, where I need to use some legacy code, which uses HttpRequestBase as method argument. The legacy code does not follow SOLID so It's impossible to extend it to use OwinRequest instead of HttpRequestBase Is there an extension (or a way) to convert an OwinRequest into a HttpRequestBase? If you have access to the IOwinContext of the request, you can use this little hack to get the HttpContextBase : HttpContextBase httpContext = context.Get<HttpContextBase>(typeof(HttpContextBase).FullName); And then, you would just: HttpRequestBase httpRequest = httpContext

Pass a parameter to OWIN host

爱⌒轻易说出口 提交于 2019-12-04 02:29:45
I'm self-hosting ASP.NET Web API and SignalR using OWIN. I start the server (on a console app) with this code: using (WebApplication.Start<Startup>(url)) { Console.WriteLine("Running..."); Console.ReadLine(); } This works fine. But now I need to pass a parameter (an object) to the Startup class. How can this be done? The WebApplication.Start method has an overload that accepts a IServiceProvider as parameter, so it is possible to inject the data I want. IServiceProvider serviceProvider = DefaultServices.Create(defaultServiceProvider => { defaultServiceProvider.AddInstance<IMyInterface>

How to get ApplicationDbContext out of the Owin pipeline

扶醉桌前 提交于 2019-12-04 01:05:53
This has to be simple, but I'm going bug-eyed trying to find the answer. How does a controller action get a reference to the per-request ApplicationDbContext that was stashed in the Owin pipeline? EDIT: Ok, I think I'm getting closer... or maybe not... All of my Googling seems to lead to this blog post , which sez to use: var dbContext = context.Get<ApplicationDbContext>(); where context is apparently an instance of Microsoft.Owin.IOwinContext . So I tried: var db = HttpContext.GetOwinContext().Get<ApplicationDbContext>(); But the Get<T> method requires a string key parameter. :( And the

Make an HTTP POST authentication basic request using Javascript

被刻印的时光 ゝ 提交于 2019-12-04 00:30:27
I want to use JavaScript to perform a POST request using the common "Authorization: Basic" method. The server hosts an OWIN C# App and on successful authentication it should give me a token in JSON format. This is the wireshark equivalent of what I want to accomplish using plain Javascript: POST /connect/token HTTP/1.1 Authorization: Basic c2lsaWNvbjpGNjIxRjQ3MC05NzMxLTRBMjUtODBFRi02N0E2RjdDNUY0Qjg= Content-Type: application/x-www-form-urlencoded Host: localhost:44333 Content-Length: 40 Expect: 100-continue Connection: Keep-Alive HTTP/1.1 100 Continue grant_type=client_credentials&scope

How to keep user login in to system and logout only after user clicks on logout button?

梦想与她 提交于 2019-12-04 00:11:46
I am using custom implementation of microsoft asp.net identity because i have custom tables that is why i have given custom implementation of all my methods IUserStore and IUserPasswordStore . Problem is when user logins then after 10 - 15 minutes login user session gets expired but what i want is unless user logs out i want to keep user login in to the system. Code: public partial class Startup { public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app

“System.MissingMemberException: The server factory could not be located” starting Microsoft.Owin self-hosted in TeamCity

怎甘沉沦 提交于 2019-12-04 00:10:37
When Teamcity runs an integration test that starts a self-hosted webapplication, the test fails with the error: System.MissingMemberException: The server factory could not be located for the given input: Microsoft.Owin.Host.HttpListener The code throwing this error is: var webApp = WebApp.Start<Startup>("http://*:52203/") The test runs fine when executed withing Visual Studio (using the Resharper test runner). Teamcity is configured to use the JetBrains.BuildServer.NUnitLauncher.exe executable to run the test. I see a lot of posts regarding this error are to do with the because the Microsoft

Websockets using OWIN

孤者浪人 提交于 2019-12-03 23:55:38
All the examples using Microsoft WebSockets over a web-api that I've seen so far use IIS, the implementation is on the get method the HTTP connection is upgraded to a websocket and an instance of websocket handler is passed to the HTTPContext public HttpResponseMessage Get() { if (HttpContext.Current.IsWebSocketRequest) { var noteHandler = new NoteSocketHandler(); HttpContext.Current.AcceptWebSocketRequest(noteHandler); } return new HttpResponseMessage(HttpStatusCode.SwitchingProtocols); } What am trying to achieve is to do the same on an OWIN pipeline. The problem am facing is the connection

Authentication using OAuth in Web API

泄露秘密 提交于 2019-12-03 23:41:58
I'm working on a project using ASP.Net MVC5 which also includes a Web API. The API will be for internal use only. I'm using the OWIN library to provider authentication. I'm having a difficult time figuring out how to correctly implement authentication through the API. I was planning on using OAuth 2.0 but the problem with OAuth is that the user needs to login through a browser page instead of a native login screen. So I was wondering if it is possible to somehow skip the browser. I've found this example which creates it's own OAuth Authorization Server. But it doesn't show how to make the

Unable to add and fetch custom claims values

孤街醉人 提交于 2019-12-03 23:33:36
问题 I am using mvc 5 with identity 2.0. I want use custom claim values over the application but I get null value. What am I doing wrong? Updated code Login Code in account controller if (!string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Password)) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var result = SignInManager.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout: false); //Generate verification token Dictionary