繁体   English   中英

WSFederation登录-Asp.net 4.6.1

[英]WSFederation Sign-in - Asp.net 4.6.1

因此,我正在尝试使用WSFederation协议对基于Web的身份验证进行分类。 我们整理了一下设置,经过一段时间后,我的Web应用程序可以访问登录页面:

Asp.net本地身份验证-根据验证过程,远程证书无效

现在,我得到一个'IDX10201:SecurityTokenHandlers都无法读取'securityToken'错误。 据我了解,我们将需要中间件来处理安全令牌。 所以我正在尝试开始:

https://www.scottbrady91.com/Katana/WS-Federation-Token-Encryption-using-Microsoft-Katana

因此,我已经在WsFederationAuthenticationOptions中设置了TokenValidationParameters选项,但是我从VisualStudio中收到一条错误消息,指出当前上下文中不存在“证书”。 我对原因感到困惑,因为我的代码与指南几乎相同。

我也想知道我们的证书是否只是配置不正确。 我遇到了一些有关ADFS的SSL准则,而且我知道我们的IT专家还没有走这条路。 我想排除这种可能的原因,但是如果有人知道是或不是原因,那可以节省我的时间,我们将不胜感激。

编辑:经过一番阅读,有些事情对我来说还不清楚? 我们使用的是ADFS服务器来处理凭据,但据我了解,ADFS还应该处理令牌,而无需进行任何其他工作。 我错了吗? 我应该使用中间件吗? 还是ADFS服务器配置有问题?

using System;
using System.Collections.Generic;
using System.Configuration;
using Microsoft.Owin.Security;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.WsFederation;
using Owin;
using System.Security.Cryptography.X509Certificates;
using System.Security;
using System.Net.Security;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.IdentityModel.Tokens;
using Microsoft.Owin;
using RCHHRATool;
using System.Net;
using System.IdentityModel.Selectors;

namespace RCHHRATool
{

    public partial class Startup
    {
        private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
        private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
        private X509Certificate2 certificate;

        public void ConfigureAuth(IAppBuilder app)
        {
            Debug.WriteLine("Configure Auth Started");
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

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

            //System.Net.ServicePointManager.ServerCertificateValidationCallback.
            //ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidationCB;
            var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            foreach(X509Certificate2 cert in store.Certificates)
            {
                Debug.WriteLine(cert.Issuer);
                if (cert.Issuer.Equals("CN=xxxxx.xxxxx.com"))
                {
                    this.certificate = new X509Certificate2(cert);
                }

            }



            app.UseWsFederationAuthentication(
                new WsFederationAuthenticationOptions
                {
                    SignInAsAuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType,
                    Wtrealm = "https://localhost:44340",
                    Wreply = "http://localhost:56879",
                    MetadataAddress = adfsMetadata,
                    AuthenticationType = "adfs",
                    SecurityTokenHandlers = new SecurityTokenHandlerCollection
                    {
                        new X509SecurityTokenHandler
                        {
                            Configuration = new SecurityTokenHandlerConfiguration
                            {
                                IssuerTokenResolver = new X509CertificateStoreTokenResolver(StoreName.Root,
                                    StoreLocation.LocalMachine)
                            }
                        }
                    }
                    //},
                    //TokenValidationParameters = new TokenValidationParameters
                    //{
                    //    ValidAudience = "https://localhost:44340/",
                    //    ValidIssuer = "xxxxx.xxxxx.com",
                    //    IssuerSigningToken = new X509SecurityToken(this.certificate)
                    //}

                });  
        }  

事实证明,asp.net(框架4.6.1)和ws-federation不能开箱即用地处理加密的安全令牌。 我遵循了一个很好的指南来解决令牌错误。 经过一些调整(观察您的证书占用量,并确保您的证书位于受信任的根目录中),我设法使身份验证工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM