我在Windows Server 2019上为ADFS v4创建自定义身份验证器时遇到麻烦。我的目标是创建自定义主身份验证器,但现在我已经决定让自定义身份验证器充当其他身份验证提供程序。我关注了Microsoft的this文章,尽管该文章指出该教程适用于2012年,但它也应该适用于2019年。我很抱歉,如果随后出现的是意识流,但是我对此并不陌生,可能在实现过程中有很多错误。
按照Microsoft的指示进行操作时,可以在主要身份验证器列表中看到该身份验证器并将其选中。但是,当我通过身份验证过程时,代码永远不会触发。我从未在项目中看到自定义HTML片段。如果我正确理解了此示例中的代码,则应该能够将身份验证器设置为主要身份验证者和only get the HTML from my authenticator。我能做的最好的事情就是,如果选择了多个主身份验证者,则将友好名称显示在可能的身份验证者列表中。
/// Returns a Dictionary containing the set of localized friendly names of the provider, indexed by lcid.
/// These Friendly Names are displayed in the "choice page" offered to the user when there is more than
/// one secondary authentication provider available.
public Dictionary<int, string> FriendlyNames
{
get
{
Dictionary<int, string> _friendlyNames = new Dictionary<int, string>();
_friendlyNames.Add(new CultureInfo("en-us").LCID, "Matt's Friendly name in the Meatadata Class");
_friendlyNames.Add(new CultureInfo("fr").LCID, "Friendly name translated to fr locale");
return _friendlyNames;
}
}
如果单击我的自定义身份验证器,它将只是错误,并且我在ADFS事件日志中得到一个条目,提示它找不到指定的用户。我以为通过使用自定义项,它将绕过任何Active Directory查找,但显然它仍在进行查找,并且从未显示过自定义登录页面。
我将代码中的每个方法都记录到Windows事件日志中,然后我会收到一条消息,提示程序进入了OnAuthenticationPipelineLoad方法。
public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)
{
//this is where AD FS passes us the config data, if such data was supplied at registration of the adapter
myNewLog.WriteEntry("Matt -> this is where AD FS passes us the config data, if such data was supplied at registration of the adapter");
}
不幸的是,这在某些时候停止了工作,我无法将其恢复,因此就好像代码不再将其放到这里一样。
我搜寻GitHub,寻找其他这样做的人,并发现了Microsoft's example provider。不幸的是,Microsoft的代码也不起作用,因此必须是我配置错误的东西,但我不知道在哪里查找。
我尝试将自定义身份验证器设置为辅助身份验证器,但在这种情况下,代码也永远不会触发。
在我的日志记录停止工作之前,我认为代码可能与AuthenticationMethods元数据有关。
/// Returns an array of strings containing URIs indicating the set of authentication methods implemented by the adapter
/// AD FS requires that, if authentication is successful, the method actually employed will be returned by the
/// final call to TryEndAuthentication(). If no authentication method is returned, or the method returned is not
/// one of the methods listed in this property, the authentication attempt will fail.
public virtual string[] AuthenticationMethods
{
get {
myNewLog.WriteEntry("Matt -> AuthenticationMethods");
return new[] { "https://example.com/myauthenticationmethod1" }; }
}
我发现提示这可能是问题here和here。它说:“ IAuthenticationAdapterMetadata:定义适配器元数据,包括适配器的名称和它支持的身份验证类型”和“同时执行全局方和依赖方MFA AdditionalAuthenticationRules声明规则集。(方框C)。如果其中一个的输出声明集规则集包含类型为“ http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod”的声明和值“ http://schemas.microsoft.com/claims/multipleauthn”,然后是MFA会参与。”
我想我什至不知道该问什么。有没有人以前创建过自定义ADFS身份验证器,然后看到此问题?有什么明显的我可以检查的原因吗?
答案 0 :(得分:0)
事实证明这是一个两部分的问题,是由于我缺乏领域知识造成的。
我将代码用作辅助身份验证器时遇到的问题与设置声明规则有关。这是本教程让我运行的Power Shell脚本:
Set-AdfsRelyingPartyTrust –TargetRelyingParty $rp –AdditionalAuthenticationRules 'c:[type == "http://schemas.microsoft.com/ws/2012/01/insidecorporatenetwork", value == "false"] => issue(type = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod", value = "http://schemas.microsoft.com/claims/multipleauthn" );'
我的问题是我从网络的内部内部而不是网络的外部进行测试,因此脚本对我来说是错误的。一旦我编辑了强制对内部用户使用MFA的规则,我的代码就会成功命中。
Set-AdfsRelyingPartyTrust –TargetRelyingParty $rp –AdditionalAuthenticationRules 'c:[type == "http://schemas.microsoft.com/ws/2012/01/insidecorporatenetwork", value == "true"] => issue(type = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod", value = "http://schemas.microsoft.com/claims/multipleauthn" );'
事实证明,我无法以我尝试的方式将代码用作主要的身份验证器。 ADFS仅允许您针对AD身份提供程序进行身份验证。 ADFS事件日志中的消息“找不到指定的用户” 是尝试绕过设置用户的步骤的结果。由于我不想为我的用户查询Active Directory,因此我会收到一个错误消息,即身份验证器找不到指定的用户...很有意义。
我真正需要的是其他身份提供者。为了我对ADFS的信任,我需要指定Active Directory以外的身份提供程序。我找到了这个here的示例。此解决方案使用asp.net网站中托管的identity server 3作为身份提供者。通过使用此解决方案,我能够为当前用户手动设置声明。
此解决方案使用的身份服务器3已过时,理想情况下,您将使用当前支持的身份服务器4。但是,identity server 4的ws-federation部分已经移到了付费墙后面。
我的依赖方信任仍然存在问题,因为当用户从依赖方访问我们的站点时,会向他们提供多个身份提供者(或ADFS称为索赔提供者)。为了防止显示此屏幕,您可以将身份服务器设置为依赖方的默认声明提供程序。
Set-AdfsRelyingPartyTrust -TargetName "Relying Party" -ClaimsProviderName ("IdentityServer")
关于什么是身份服务器以及它正在尝试解决的问题here
有很好的文章。还有一个开放源代码存储库,用于填充我未使用的身份服务器4 here的ws-federation