owin

Got 400 error for pre-flight options CORS token request from OWIN-based WebAPI

可紊 提交于 2019-12-04 12:37:09
It is really strange. I tried to make a CORS request to WebAPI2 (OWIN-based) to gain authentication token. It always fails every other times. like 1st request fails, but 2nd request will go through. And the 3rd fails, but the 4th will go through. I don't understand why it was working half of the times. I check the browser request (chrome). The one got failed always goes by OPTIONS method. The one went through always goes by POST. But I always use post method with headers 'Content-Type': 'application/x-www-form-urlencoded' So I guess the question is why sometime Chrome/fire fox send preflight

Custom parameter with Microsoft.Owin.Security.OpenIdConnect and AzureAD v 2.0 endpoint

随声附和 提交于 2019-12-04 12:23:55
I am migrating my Azure AD secured application to the v2.0 endpoint. I need to pass a custom parameter to the reply uri. With former Azure AD endpoint I did it by adding a usual query parameter to the reply url. e.g. https://myserver.com/myredirect_uri?mycustomparamerter=myvalue Unfortunately, with endpoint 2.0 I received an error saying that the reply uri does not match the one registered. Of course my custom parameter value is dynamic and I cannot hardcode it. I was looking to exploit the 'state' parameter described in OAUTH flow . However, I am using Microsoft.Owin.Security.OpenIdConnect

Owin Authentication In MVC and Web Api

江枫思渺然 提交于 2019-12-04 12:23:39
I'm trying to use the same authentication between the MVC controllers and the Web Api controllers. The Web api is in the same project, just in an /Controllers/API/ folder. I can't seem to figure out how to authenticate using OWIN, when I logged in through MVC and created a claim and a cookie like the example below. var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name,"Admin"), new Claim(ClaimTypes.Role,"Administrator") , "ApplicationCookie"); var ctx = Request.GetOwinContext(); var authManager = ctx.Authentication; authManager.SignIn(identity); return RedirectToAction("Index",

Response body for request/response Logging

六眼飞鱼酱① 提交于 2019-12-04 12:18:36
问题 I'm trying to write a Owin midleware component that would LOG every incoming request and response to the database. Here's how far I managed to get. I got stuck on reading the response.body. Says: Stream does not support reading. How can I read the Response.Body ? public class LoggingMiddleware : OwinMiddleware { private static Logger log = LogManager.GetLogger("WebApi"); public LoggingMiddleware(OwinMiddleware next, IAppBuilder app) : base(next) { } public override async Task Invoke

How should I store per request data when using OWIN to Self-Host ASP.NET Web API

巧了我就是萌 提交于 2019-12-04 11:29:49
I'm in the process of converting my ASP.NET Web API from being IIS hosted to being self hosted. In one of my DelegatingHandlers I set the current user based on the token from the HTTP header. I've been using HttpContext.Current.Items to store this information, but that isn't available under self hosting. What is the correct way to store per request data that can be accessed anywhere in my application? The Request message has a Properties collection. 来源: https://stackoverflow.com/questions/19788153/how-should-i-store-per-request-data-when-using-owin-to-self-host-asp-net-web-api

Replace IExceptionHandler in Web Api 2.2 with OWIN middleware exception handler

浪子不回头ぞ 提交于 2019-12-04 11:09:30
问题 I have created an OWIN middleware to catch exceptions. The middleware does nothing really but wrap the next call with try catch like this try { await _next(environment) } catch(Exception exception){ // handle exception } The problem is that the middlware is not capturing the exception because the exception is been handled by the default implementation of IExceptionHandler which returns an xml with the stack trace. I understand that I can replace the default IExceptionHandler implementation

Owin WS-Federation setting up token sliding expiration

心不动则不痛 提交于 2019-12-04 10:14:48
Can somebody explain how to implement sliding expiration using the new Owin WS-Federation plugin? On the client side, at WS-Fedeartion configuration I see that there are some events like : Notifications = new WsFederationAuthenticationNotifications { SecurityTokenReceived = ..., AuthenticationFailed = ..., RedirectToIdentityProvider = ..., MessageReceived = ..., SecurityTokenValidated = .... }, But because the lack of documentation I can't really figure it out where an how? At the moment my STS is issuing tokens with absolute expiration : protected override Lifetime GetTokenLifetime(Lifetime

C# Owin WebApp: Parsing POST Requests?

不问归期 提交于 2019-12-04 10:13:27
I would like some help on parsing HTTP POST requests in a C# console application. The app runs a 'web-server' using Owin. Details of the application are available here and the current 'stable version' of the relevant code is here . I am extending the above application to enable configuration through the web UI. For example, the app currently reports a large number of parameters. I would like the end-user to be able to select which parameters get reported over the network. Towards this, I made some modifications to the code above: using Microsoft.Owin; using Owin; ......... [assembly:

Use Windows Authentication with OAuth 2.0

[亡魂溺海] 提交于 2019-12-04 09:37:49
问题 I have set up an OWIN authorization server and several resource servers exposing ASP.NET Web APIs. I am serving up a JWT from the authorization server that is specific to each resource server (the idea being that each resource server needs custom claims wrapped up in its token). These servers are all in an intranet environment where we historically have used Windows Authentication (Kerberos) to provide a single sign-on experience. This feature has been lost in my implementation because I am

How to proper log every exception using OWIN

核能气质少年 提交于 2019-12-04 09:05:03
问题 my question should be quite simple, but unfortunately I had no luck in solving it. Basically, I have some Web API controllers hosted by OWIN and deployed on Azure. I really need to track down exceptions that occur in each middleware (for example OAuthAuthorizationServerProvider or SignalR Persistent Connections ), but I definitely don't have a clue on how to achieve it. I tried Elmah, but it doesn't seem to work properly with OWIN due to lacking HttpContext . I tried using log4net, but I'm