【问题标题】:Microsoft.Owin.Security.WsFederation Custom Authorize Attribute API RedirectMicrosoft.Owin.Security.WsFederation 自定义授权属性 API 重定向
【发布时间】:2015-12-17 20:36:19
【问题描述】:

所以我们在我们的应用程序中集成了Okta,以利用OWIN 堆栈和Microsoft.Owin.Security.WsFederation nuget 包的SSO 解决方案。总体而言,它似乎运行良好,但是当将 WebApi 的授权属性添加到组合中时,我们遇到了问题。自定义授权属性按设计为通过字符串参数提供的权限工作,但是问题似乎与返回 401 response 的默认行为有关。似乎这个 401 在全球范围内受到关注,因为我从未点击我的自定义 OWIN middleware 组件进行登录(即:重定向到 Okta)但是当返回 302 触发重定向到时 API 请求仍然失败Okta。我读过的每篇文章都表示要关注 Brock Allen 的 this 博客文章,但是正如我提到的,重定向永远不会触发此代码。我考虑过构建一个 Angular 拦截器,但我根本不喜欢这种方法,所以我现在从Authorize 属性返回一个403 (Forbidden),这并不理想但可行。 This SO 帖子似乎是关于这个问题的主要讨论,但我没有按照那里的建议走运。这是迄今为止使用的中间件代码,有人对如何排除 /api 路由重定向到 Okta 有任何想法或想法吗?

        var fileSystem = new PhysicalFileSystem(@".\wwwroot");

        var options = new FileServerOptions()
        {
            FileSystem = fileSystem,
            EnableDefaultFiles = true,
            EnableDirectoryBrowsing = true,
        };

        app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);

        app.UseCookieAuthentication(
            new CookieAuthenticationOptions
            {
                AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
            });

        app.UseWsFederationAuthentication(
                new WsFederationAuthenticationOptions
                {
                    MetadataAddress = ConfigurationManager.AppSettings["MetadataAddress"],
                    Wtrealm = ConfigurationManager.AppSettings["Wtrealm"],
                    TokenValidationParameters =
                    {
                        ValidAudience = ConfigurationManager.AppSettings["ValidAudience"]
                    }
                });


        app.Map("/api", x =>
        {
            dependencyResolver = x.UseApi();
        });

        app.UseFileServer(options);

【问题讨论】:

  • 我建议您查看cloudidentity.com/blog/2014/04/28/…。虽然这篇文章使用了 OIDC,但这种方法也应该适用于 WSFed。
  • @vibronet 我希望您将此作为答案发布,以便您获得应得的荣誉。那篇文章解决了我的问题,因为我不知道 HostAuthentication 属性。如果你发布它,我会给你答案。再次感谢该博客从未出现在我的研究中!

标签: angularjs asp.net-web-api2 owin ws-federation okta


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 2011-07-01
    • 1970-01-01
    • 2017-08-29
    • 2015-03-03
    相关资源
    最近更新 更多