Tag: owin

如何安全地拦截自定义Owin中间件中的响应流

我正在尝试编写一个简单的OWIN中间件,以拦截响应流。 我想要做的是用自定义的基于Stream的类替换原始流,在那里我将能够拦截对响应流的写入。 但是,我遇到了一些问题,因为我无法知道响应是否已被链中的内部中间件组件完全写入。 永远不会调用Stream的Dispose重写。 所以我不知道什么时候执行我的处理,这应该发生在响应流的末尾。 这是一个示例代码: public sealed class CustomMiddleware: OwinMiddleware { public CustomMiddleware(OwinMiddleware next) : base(next) { } public override async Task Invoke(IOwinContext context) { var request = context.Request; var response = context.Response; // capture response stream var vr = new MemoryStream(); var responseStream = new ResponseStream(vr, response.Body); response.OnSendingHeaders(state => { var resp = […]

WebApi.Owin中的SuppressDefaultHostAuthentication还禁止webapi之外的身份validation

我遇到了一个解决方案的问题,我使用Visual Studio SPA模板中的部件在WebApi中使用Oauth身份validation使用Account Controller。 app.UseOAuthBearerTokens(OAuthOptions); 然后我在owin webapi注册中正在做 config.SuppressDefaultHostAuthentication(); 但这也会阻止webapi环境之外的默认cookie身份validation。 这是意图吗? 如果是这样,我如何设置WebApi来抑制cookie身份validation,但它仍然在其他请求的环境中活动?

在ASP.NET 4.5项目中使用wwwroot文件夹(ASP.NET Core样式)

我非常喜欢新的asp.net(asp.net 5 \ core 1.0)web应用程序的方法,其中wwwroot文件夹是根目录,只有静态文件才能提供。 可以通过路由或其他配置在asp.net 4.5项目中使用wwwroot文件夹以类似的方式运行,这样静态文件只能从中提供,而且它是静态文件的webapp的“根”吗? (我在询问这个问题时的部分动机是我在VS2015中的asp.net 5项目中托管了一个角度应用程序,但是我需要将其转移到asp.net 4.5项目中,但是希望将现有结构保留在磁盘上) 尝试使用OWIN 我尝试使用一个空的ASP.NET 4.5 Web应用程序项目和OWIN。 所以我的文件夹结构有我的角度应用程序,在项目文件夹的wwwroot文件夹中有一个主index.html文件。 项目的根目录中没有HTML文件。 我通过nuget和以下启动文件添加了OWIN: [assembly: OwinStartup(typeof(MyApp.UI.Startup))] namespace MyApp.UI { public class Startup { public void Configuration(IAppBuilder app) { string root = AppDomain.CurrentDomain.BaseDirectory; var physicalFileSystem = new PhysicalFileSystem(Path.Combine(root, “wwwroot”)); var options = new FileServerOptions { EnableDefaultFiles = true, FileSystem = physicalFileSystem }; options.StaticFileOptions.FileSystem […]

如何使用刷新令牌续订访问令牌?

我正在使用带有OWIN的 ASP.NET MVC 5 。 我做了很多研究,但没有找到如何使用刷新令牌续订访问令牌。 我的方案是:用户第一次访问我的应用时,他或她授予访问我读取API返回的刷新令牌的帐户的权限。 当用户返回我的应用程序时,我需要根据“刷新令牌”刷新访问令牌。 有人可以提供一些代码吗? 这是我到目前为止所取得的成就: Startup.Auth.cs: var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions { Caption = “Google+”, ClientId = Parameters.Instance.Authentication.oAuth.GooglePlus.ClientId, ClientSecret = Parameters.Instance.Authentication.oAuth.GooglePlus.ClientSecret, CallbackPath = new PathString(“/oauth-login-return”), Provider = new GoogleOAuth2AuthenticationProvider { OnAuthenticated = async context => { context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Identity.FindFirstValue(ClaimTypes.Name))); context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Identity.FindFirstValue(ClaimTypes.Email))); context.Identity.AddClaim(new Claim(“picture”, context.User.GetValue(“picture”).ToString())); context.Identity.AddClaim(new Claim(“profile”, context.User.GetValue(“profile”).ToString())); context.Identity.AddClaim( new […]