当前位置: 首页>>代码示例>>C#>>正文


C# IServiceProvider.GetAssertionConsumerServiceLocation方法代码示例

本文整理汇总了C#中IServiceProvider.GetAssertionConsumerServiceLocation方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetAssertionConsumerServiceLocation方法的具体用法?C# IServiceProvider.GetAssertionConsumerServiceLocation怎么用?C# IServiceProvider.GetAssertionConsumerServiceLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceProvider的用法示例。


在下文中一共展示了IServiceProvider.GetAssertionConsumerServiceLocation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AuthnRequest

        /// <summary>
        /// Initializes a new instance of the AuthnRequest class.
        /// </summary>
        /// <param name="identityProvider">
        /// IdentityProvider to receive the AuthnRequest
        /// </param>
        /// <param name="serviceProvider">
        /// ServiceProvider to issue the AuthnRequest
        /// </param>
        /// <param name="parameters">
        /// NameValueCollection of varying parameters for use in the 
        /// construction of the AuthnRequest.
        /// </param>
        /// <param name="saml2Utils">Utilities class</param>
        public AuthnRequest(IIdentityProvider identityProvider, IServiceProvider serviceProvider, NameValueCollection parameters, Saml2Utils saml2Utils)
        {
            xml = new XmlDocument();
            xml.PreserveWhitespace = true;

            nsMgr = new XmlNamespaceManager(xml.NameTable);
            nsMgr.AddNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
            nsMgr.AddNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");

            Id = saml2Utils.GenerateId();
            IssueInstant = saml2Utils.GenerateIssueInstant();
            Issuer = serviceProvider.EntityId;

            if (parameters != null)
            {
                AllowCreate = saml2Utils.GetBoolean(parameters[Saml2Constants.AllowCreate]);
                AssertionConsumerServiceIndex = parameters[Saml2Constants.AssertionConsumerServiceIndex];
                Binding = parameters[Saml2Constants.Binding];
                Consent = parameters[Saml2Constants.Consent];
                Destination = parameters[Saml2Constants.Destination];
                ForceAuthn = saml2Utils.GetBoolean(parameters[Saml2Constants.ForceAuthn]);
                IsPassive = saml2Utils.GetBoolean(parameters[Saml2Constants.IsPassive]);
                NameIDPolicyFormat = parameters[Saml2Constants.NameIDPolicyFormat];
            }

            string assertionConsumerSvcUrl = null;
            if (!String.IsNullOrEmpty(Binding))
            {
                if (!String.IsNullOrEmpty(AssertionConsumerServiceIndex))
                {
                    // find assertion consumer service location by binding and index.
                    assertionConsumerSvcUrl = serviceProvider.GetAssertionConsumerServiceLocation(Binding,
                                                                                                  AssertionConsumerServiceIndex);
                }
                else
                {
                    // find assertion consumer service location by binding only, using first found.
                    assertionConsumerSvcUrl = serviceProvider.GetAssertionConsumerServiceLocation(Binding);
                }
            }

            // neither index nor binding, throw exception
            if (String.IsNullOrEmpty(AssertionConsumerServiceIndex) && String.IsNullOrEmpty(assertionConsumerSvcUrl))
            {
                throw new Saml2Exception(Resources.AuthnRequestAssertionConsumerServiceNotDefined);
            }

            // If destination not specified, use SSO location by binding
            if (string.IsNullOrEmpty(Destination))
            {
                Destination
                    = identityProvider.GetSingleSignOnServiceLocation(parameters[Saml2Constants.RequestBinding]);

                if (string.IsNullOrEmpty(Destination))
                {
                    // default to HttpRedirect
                    Destination = identityProvider.GetSingleSignOnServiceLocation(Saml2Constants.HttpRedirectProtocolBinding);
                }
            }

            // Get RequestedAuthnContext if parameters are available...
            RequestedAuthnContext reqAuthnContext = GetRequestedAuthnContext(serviceProvider, parameters);

            // Generate the XML for the AuthnRequest...
            var rawXml = new StringBuilder();
            rawXml.Append("<samlp:AuthnRequest ");
            rawXml.Append(" xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\"");
            rawXml.Append(" ID=\"" + Id + "\"");
            rawXml.Append(" Version=\"2.0\"");
            rawXml.Append(" IssueInstant=\"" + IssueInstant + "\"");
            rawXml.Append(" IsPassive=\"" + IsPassive.ToString().ToLower() + "\"");
            rawXml.Append(" ForceAuthn=\"" + ForceAuthn.ToString().ToLower() + "\"");

            if (!String.IsNullOrEmpty(Consent))
            {
                rawXml.Append(" Consent=\"" + Consent + "\"");
            }

            if (!String.IsNullOrEmpty(Destination))
            {
                rawXml.Append(" Destination=\"" + Destination + "\"");
            }

            if (!String.IsNullOrEmpty(assertionConsumerSvcUrl))
            {
                rawXml.Append(" ProtocolBinding=\"" + Binding + "\"");
//.........这里部分代码省略.........
开发者ID:agascon,项目名称:Fedlet,代码行数:101,代码来源:AuthnRequest.cs


注:本文中的IServiceProvider.GetAssertionConsumerServiceLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。