【问题标题】:Why does WS-Federation require Microsoft.AspNetCore.DataProtection.Abstractions NuGet package?为什么 WS-Federation 需要 Microsoft.AspNetCore.DataProtection.Abstractions NuGet 包?
【发布时间】:2020-02-03 14:27:56
【问题描述】:

我一直在学习如何让 WS-Federation 在没有身份的情况下工作,并且对于初始设置,我使用了以下指南:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/ws-federation?view=aspnetcore-3.0

在很长一段时间内,我一直遇到错误,但偶然发现了一个解决方案,即包含 Microsoft.AspNetCore.DataProtection.Abstractions NuGet 包。

指南中的任何地方都没有提到这一点,我发现只有一篇文章提到过与 WS-Federation 相关的内容:https://github.com/dotnet/aspnetcore/issues/18639

这个 NuGet 包有什么作用,为什么需要它来使 WS-Federation 工作?这甚至是正确的设置方法吗?

【问题讨论】:

  • 我遇到了同样的问题。它在本地工作,但在测试服务器上失败。遇到这些类型的运行时问题肯定会令人沮丧。

标签: c# asp.net-core authorization single-sign-on ws-federation


【解决方案1】:

可以找到源代码on github here

实际上,它提供了一个接口IDataProtectorIDataProtectionProvider

namespace Microsoft.AspNetCore.DataProtection
{
    /// <summary>
    /// An interface that can provide data protection services.
    /// </summary>
    public interface IDataProtector : IDataProtectionProvider
    {
        /// <summary>
        /// Cryptographically protects a piece of plaintext data.
        /// </summary>
        /// <param name="plaintext">The plaintext data to protect.</param>
        /// <returns>The protected form of the plaintext data.</returns>
        byte[] Protect(byte[] plaintext);

        /// <summary>
        /// Cryptographically unprotects a piece of protected data.
        /// </summary>
        /// <param name="protectedData">The protected data to unprotect.</param>
        /// <returns>The plaintext form of the protected data.</returns>
        /// <exception cref="System.Security.Cryptography.CryptographicException">
        /// Thrown if the protected data is invalid or malformed.
        /// </exception>
        byte[] Unprotect(byte[] protectedData);
    }
}
namespace Microsoft.AspNetCore.DataProtection
{
    /// <summary>
    /// An interface that can be used to create <see cref="IDataProtector"/> instances.
    /// </summary>
    public interface IDataProtectionProvider
    {
        /// <summary>
        /// Creates an <see cref="IDataProtector"/> given a purpose.
        /// </summary>
        /// <param name="purpose">
        /// The purpose to be assigned to the newly-created <see cref="IDataProtector"/>.
        /// </param>
        /// <returns>An IDataProtector tied to the provided purpose.</returns>
        /// <remarks>
        /// The <paramref name="purpose"/> parameter must be unique for the intended use case; two
        /// different <see cref="IDataProtector"/> instances created with two different <paramref name="purpose"/>
        /// values will not be able to decipher each other's payloads. The <paramref name="purpose"/> parameter
        /// value is not intended to be kept secret.
        /// </remarks>
        IDataProtector CreateProtector(string purpose);
    }
}

它们都是 WS-Federation 正在实现(一个或另一个或两者)或正在使用的某些实现的抽象(期望来自某种 DI 容器或构造函数)。无论如何,如果没有它,您将无法正常工作。

设置方法是同时安装nuget包from here

【讨论】:

  • 谢谢。我的代码中没有写IDataProtectorIDataProtectionProvider。所以我理解它的方式是在Microsoft.AspNetCore.Authentication.WsFederation NuGet 包的代码中的某个地方,正在使用来自...DataProtection.Abstractions 包的接口?如果是这样,我想知道为什么微软的指南没有提到这些接口或...DataProtection.Abstractions 包?
  • 确实如此。在 WsFederation 中的某个地方,使用了这些抽象。您可以克隆 WsFederation 存储库以确保,但我很确定情况确实如此,而且这只是缺少文档问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-26
相关资源
最近更新 更多