简体   繁体   English

ITfoxtec.Identity.Saml2 无效 URI 问题

[英]ITfoxtec.Identity.Saml2 Invalid URI Issue

When i use <TargetFramework>net462</TargetFramework> for my Okta SAML implementation this throw a Invalid URL when it this new Saml2AuthnRequest(config);当我将<TargetFramework>net462</TargetFramework>用于我的 Okta SAML 实现时,当它使用这个new Saml2AuthnRequest(config); but on my first try using this code on netcoreapp3.1` this worked perfectly fine.但在我第一次尝试在 netcoreapp3.1 上使用此代码时,它工作得非常好。 Please let me know if i miss something thank you.如果我错过了什么,请告诉我谢谢。

在此处输入图像描述

在此处输入图像描述

[HttpGet, AllowAnonymous]
    public IActionResult Index(string returnUrl = null)
    {
        try
        {
            var config = GetSAMLConfig();
            var binding = new Saml2RedirectBinding();
            binding.SetRelayStateQuery(new Dictionary<string, string> { { relayStateReturnUrl, returnUrl ?? Url.Content("~/") } });
            var request = new Saml2AuthnRequest(config);
            return binding.Bind(request).ToActionResult();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }

在此处输入图像描述

   private Saml2Configuration GetSAMLConfig()
    {
        var config = new Saml2Configuration();
        config.AllowedAudienceUris.Add("Okta_SAML_Example");
        config.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;
        config.RevocationMode = X509RevocationMode.NoCheck;

        var entityDescriptor = new EntityDescriptor();
        entityDescriptor.ReadIdPSsoDescriptorFromUrl(new Uri("https://---------.okta.com/app/exk2b0b7dibno7rOB5d6/sso/saml/metadata"));
        if (entityDescriptor.IdPSsoDescriptor != null)
        {
            config.SingleSignOnDestination = entityDescriptor.IdPSsoDescriptor.SingleSignOnServices.First().Location;
            config.SignatureValidationCertificates.AddRange(entityDescriptor.IdPSsoDescriptor.SigningCertificates);
        }
        else
        {
            throw new Exception("IdPSsoDescriptor not loaded from metadata.");
        }

        return config;
    }

Actual exception实际异常

System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at ITfoxtec.Identity.Saml2.Configuration.Saml2IdentityConfiguration.GetAudienceRestriction(Boolean audienceRestricted, IEnumerable`1 allowedAudienceUris)
   at ITfoxtec.Identity.Saml2.Configuration.Saml2IdentityConfiguration.GetIdentityConfiguration(Saml2Configuration config)
   at ITfoxtec.Identity.Saml2.Saml2Request..ctor(Saml2Configuration config)
   at ITfoxtec.Identity.Saml2.Saml2AuthnRequest..ctor(Saml2Configuration config)
   at SAMLNet461.Controllers.HomeController.Index(String returnUrl) in D:\REPO\PELICAN\LOCAL\SAML.RND - CompanyAcccounts adjustment\SAML.Demo\SAMLNet461\Controllers\HomeController.cs:line 69
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()

The code looks correct.代码看起来正确。

Maybe it is a TLS version issue.可能是 TLS 版本问题。

An alternative solution is to download the metadata in your code and add the metadata string to the ITfoxtec Identity SAML 2.0 library:另一种解决方案是在您的代码中下载元数据并将元数据字符串添加到ITfoxtec Identity SAML 2.0库:

var idPMetadataXml = "... downloaded metadata ...";
var entityDescriptor = new EntityDescriptor();
entityDescriptorReadIdPSsoDescriptor(idPMetadataXml);
...

Updated:更新:

The error seams to be in relation to Audience Restriction:错误接缝与观众限制有关:

config.AllowedAudienceUris.Add("Okta_SAML_Example"); 

The audience have to be a URI in a .NET Framework application.受众必须是 .NET 框架应用程序中的 URI。 Plain text strings are only supported in .NET Core and .NET 5.0.纯文本字符串仅在 .NET Core 和 .NET 5.0 中受支持。

.NET Framework sample: https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2/tree/master/test/TestWebApp .NET 框架示例: https://github.com/ITfoxtec/ITfoxtec.Identity.Saml2/tree/master/test/TestWebApp

I had the same issue and it was caused by "GetAudienceRestriction() method".我有同样的问题,它是由“GetAudienceRestriction() 方法”引起的。 Changing issuer name from "application-name" to "https://application-name" helped.将发行者名称从“application-name”更改为“https://application-name”有帮助。 Don't forget to change your name on your Identity Provider side (Okta, Ping Identity etc.) consistently.不要忘记在身份提供者端(Okta、Ping Identity 等)始终更改您的名称。 Now exception is not thrown anymore.现在不再抛出异常。

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

相关问题 使用 ITfoxtec.Identity.Saml2 登录用户 - Use ITfoxtec.Identity.Saml2 to login user Map SAML 声明使用 ITfoxtec.Identity.Saml2 - Map SAML claims using ITfoxtec.Identity.Saml2 User.Identity.IsAuthenticated 在使用 ITFoxtec 的 SAML 2.0 中始终为假 - User.Identity.IsAuthenticated Always false in SAML 2.0 using ITFoxtec ValidateRelyingParty方法从itfoxtec-identity-saml2的哪里派生? - Where does the method ValidateRelyingParty derive from in itfoxtec-identity-saml2? ITfoxtec.Identity.Saml2.Saml2RequestException:“不完全是一个断言元素。” - ITfoxtec.Identity.Saml2.Saml2RequestException: 'There is not exactly one Assertion element.' ITFOXTEC SAML2 CORE 示例无法编译 - ITFOXTEC SAML2 CORE example will not compile 使用 ASP.net 核心身份和 itfoxtec 与 okta 声称失踪 - claims missing using ASP.net core identity and itfoxtec with okta 使用 ITfoxtec 将经过身份验证的用户从具有 SAML SSO 的外部 SP 登录到托管 SP - Sign in an Authenticated User from External SP with SAML SSO using ITfoxtec to the managed SP Asp.net 身份电子邮件确认令牌的问题:“无效令牌” - Issue with Asp.net identity Email Confirmation Token: “Invalid Token” 无效的 Uri : uri 方案无效 - Invalid Uri : The uri scheme is not valid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM