共用方式為


在 Windows Server 中建置 AD FS 的自定義驗證方法

本逐步解說提供在 Windows Server 2012 R2 中實作 AD FS 自定義驗證方法的指示。 如需詳細資訊,請參閱 其他驗證方法

Warning

您可以在這裏建置的範例僅供教育之用。  這些指示適用於最簡單、最最少的實作,可以公開模型的必要元素。  沒有驗證後端、錯誤處理或組態數據。

設定開發環境

此逐步解說會使用 Visual Studio 2012。 您可以使用任何可建立適用於 Windows 之 .NET 類別的開發環境來建置專案。 專案必須以 .NET 4.5 為目標,因為 BeginAuthenticationTryEndAuthentication 方法會使用 System.Security.Claims.Claim 類型,這是 .NET Framework 4.5 版的一部分。 專案需要一個資料來源。

參考 dll 哪裡可以找到它 必要條件
Microsoft.IdentityServer.Web.dll dll 位於已安裝 AD FS 的 Windows Server 2012 R2 伺服器上 %windir%\ADFS。

這個 dll 必須複製到開發環境,並在專案中建立一個明確的參考。

介面類型,包括IAuthenticationContext、IProofData

建立提供者

  1. 在 Visual Studio 2012:選擇 [檔案]->[新增]->[專案]...

  2. 選取 [類別庫],並確定您是以 .NET 4.5 為目標。

    [新增專案] 對話框的螢幕快照,其中顯示已選取 [類別庫] 選項。

  3. 從已安裝 AD FS 的 Windows Server 2012 R2 伺服器上的 %windir%\ADFS 建立 Microsoft.IdentityServer.Web.dll 複本,並將其貼到開發電腦上的 Project 資料夾中。

  4. [方案總管] 中,以滑鼠右鍵按一下 [參考 ] 和 [新增參考...]

  5. 瀏覽至您本機 的Microsoft.IdentityServer.Web.dll 副本,然後 新增...

  6. 按一下 確定 以確認新參照:

    [參考管理員] 對話框的螢幕快照,其中顯示已選取 Microsoft.IdentityServer.Web.dll。

    您現在應該已設置好以處理提供者所需的所有類型。

  7. 將新類別新增至您的專案 (右鍵按一下您的專案, 新增...班級...並給它一個類似 MyAdapter 的名稱,如下所示:

    [新增專案] 對話框的螢幕快照,其中已選取 [類別] 選項。

  8. 在新檔案MyAdapter.cs中,將現有的程式代碼取代為下列專案:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Globalization;
    using System.IO;
    using System.Net;
    using System.Xml.Serialization;
    using Microsoft.IdentityServer.Web.Authentication.External;
    using Claim = System.Security.Claims.Claim;
    
    namespace MFAadapter
    {
        class MyAdapter : IAuthenticationAdapter
        {
            public IAuthenticationAdapterMetadata Metadata
            {
                //get { return new <instance of IAuthenticationAdapterMetadata derived class>; }
            }
    
            public IAdapterPresentation BeginAuthentication(Claim identityClaim, HttpListenerRequest request, IAuthenticationContext authContext)
            {
                //return new instance of IAdapterPresentationForm derived class
            }
    
            public bool IsAvailableForUser(Claim identityClaim, IAuthenticationContext authContext)
            {
                return true; //its all available for now
            }
    
            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
            }
    
            public void OnAuthenticationPipelineUnload()
            {
    
            }
    
            public IAdapterPresentation OnError(HttpListenerRequest request, ExternalAuthenticationException ex)
            {
                //return new instance of IAdapterPresentationForm derived class
            }
    
            public IAdapterPresentation TryEndAuthentication(IAuthenticationContext authContext, IProofData proofData, HttpListenerRequest request, out Claim[] outgoingClaims)
            {
                //return new instance of IAdapterPresentationForm derived class
            }
    
        }
    }
    
  9. 我們還沒有準備好建置...還有兩個介面可供使用。

    將兩個類別新增至您的專案:一個是用於元數據,另一個用於呈現表單。 您可以在與上述類別相同的檔案中新增這些專案。

    class MyMetadata : IAuthenticationAdapterMetadata
    {
    
    }
    
    class MyPresentationForm : IAdapterPresentationForm
    {
    
    }
    
  10. 接下來,您可以為每個項目新增必要的成員。首先,添加元數據(含有實用的內嵌註解)。

    class MyMetadata : IAuthenticationAdapterMetadata
    {
        //Returns the name of the provider that will be shown in the AD FS management UI (not visible to end users)
        public string AdminName
        {
            get { return "My Example MFA Adapter"; }
        }
    
        //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 { return new[] { "http://example.com/myauthenticationmethod1", "http://example.com/myauthenticationmethod2" }; }
        }
    
        /// Returns an array indicating which languages are supported by the provider. AD FS uses this information
        /// to determine the best language\locale to display to the user.
        public int[] AvailableLcids
        {
            get
            {
                return new[] { new CultureInfo("en-us").LCID, new CultureInfo("fr").LCID};
            }
        }
    
        /// 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, "Friendly name of My Example MFA Adapter for end users (en)");
                _friendlyNames.Add(new CultureInfo("fr").LCID, "Friendly name translated to fr locale");
                return _friendlyNames;
            }
        }
    
        /// Returns a Dictionary containing the set of localized descriptions (hover over help) of the provider, indexed by lcid. 
        /// These descriptions are displayed in the "choice page" offered to the user when there is more than one 
        /// secondary authentication provider available.
        public Dictionary<int, string> Descriptions
        {
            get 
            {
                Dictionary<int, string> _descriptions = new Dictionary<int, string>();
                _descriptions.Add(new CultureInfo("en-us").LCID, "Description of My Example MFA Adapter for end users (en)");
                _descriptions.Add(new CultureInfo("fr").LCID, "Description translated to fr locale");
                return _descriptions; 
            }
        }
    
        /// Returns an array indicating the type of claim that the adapter uses to identify the user being authenticated.
        /// Note that although the property is an array, only the first element is currently used.
        /// MUST BE ONE OF THE FOLLOWING
        /// "http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname"
        /// "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"
        /// "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"
        /// "http://schemas.microsoft.com/ws/2008/06/identity/claims/primarysid"
        public string[] IdentityClaims
        {
            get { return new[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn" }; }
        }
    
        //All external providers must return a value of "true" for this property.
        public bool RequiresIdentity
        {
            get { return true; }
        }
    }
    

    現在,您應該能夠在IAuthenticationAdapter 上按下 F12 (以滑鼠右鍵按兩下 – 移至定義),以查看一組必要的介面成員。

    接下來,您可以執行這些實作。

  11. 以下內容替換您的類別的整個內容:

    namespace MFAadapter
    {
        class MyAdapter : IAuthenticationAdapter
        {
            public IAuthenticationAdapterMetadata Metadata
            {
                //get { return new <instance of IAuthenticationAdapterMetadata derived class>; }
            }
    
            public IAdapterPresentation BeginAuthentication(Claim identityClaim, HttpListenerRequest request, IAuthenticationContext authContext)
            {
                //return new instance of IAdapterPresentationForm derived class
            }
    
            public bool IsAvailableForUser(Claim identityClaim, IAuthenticationContext authContext)
            {
                return true; //its all available for now
            }
    
            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
            }
    
            public void OnAuthenticationPipelineUnload()
            {
    
            }
    
            public IAdapterPresentation OnError(HttpListenerRequest request, ExternalAuthenticationException ex)
            {
                //return new instance of IAdapterPresentationForm derived class
            }
    
            public IAdapterPresentation TryEndAuthentication(IAuthenticationContext authContext, IProofData proofData, HttpListenerRequest request, out Claim[] outgoingClaims)
            {
                //return new instance of IAdapterPresentationForm derived class
            }
        }
    }
    

    接下來,簡報表單:

    class MyPresentationForm : IAdapterPresentationForm
    {
        /// Returns the HTML Form fragment that contains the adapter user interface. This data will be included in the web page that is presented
        /// to the cient.
        public string GetFormHtml(int lcid)
        {
            string htmlTemplate = Resources.FormPageHtml; //todo we will implement this
            return htmlTemplate;
        }
    
        /// Return any external resources, ie references to libraries etc., that should be included in
        /// the HEAD section of the presentation form html.
        public string GetFormPreRenderHtml(int lcid)
        {
            return null;
        }
    
        //returns the title string for the web page which presents the HTML form content to the end user
        public string GetPageTitle(int lcid)
        {
            return "MFA Adapter";
        }
    }
    
  12. 請注意上面 Resources.FormPageHtml 元素的「待辦事項」。 您可以在一分鐘內修正它,但首先讓我們根據新實作的類型,將最終必要的 return 語句新增至初始 MyAdapter 類別。 若要這樣做,請將下列內容新增至您現有的 IAuthenticationAdapter 實作:

    class MyAdapter : IAuthenticationAdapter
    {
        public IAuthenticationAdapterMetadata Metadata
        {
            //get { return new <instance of IAuthenticationAdapterMetadata derived class>; }
            get { return new MyMetadata(); }
        }
    
        public IAdapterPresentation BeginAuthentication(Claim identityClaim, HttpListenerRequest request, IAuthenticationContext authContext)
        {
            //return new instance of IAdapterPresentationForm derived class
            return new MyPresentationForm();
        }
    
        public bool IsAvailableForUser(Claim identityClaim, IAuthenticationContext authContext)
        {
            return true; //its all available for now
        }
    
        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
        }
    
        public void OnAuthenticationPipelineUnload()
        {
    
        }
    
        public IAdapterPresentation OnError(HttpListenerRequest request, ExternalAuthenticationException ex)
        {
            //return new instance of IAdapterPresentationForm derived class
            return new MyPresentationForm();
        }
    
        public IAdapterPresentation TryEndAuthentication(IAuthenticationContext authContext, IProofData proofData, HttpListenerRequest request, out Claim[] outgoingClaims)
        {
            //return new instance of IAdapterPresentationForm derived class
            outgoingClaims = new Claim[0];
            return new MyPresentationForm();
        }
    
    }
    
  13. 接下來是包含 HTML 片段的資源檔案。 使用下列內容,在您的項目資料夾中建立新的文字檔:

    <div id="loginArea">
        <form method="post" id="loginForm" >
            <!-- These inputs are required by the presentation framework. Do not modify or remove -->
            <input id="authMethod" type="hidden" name="AuthMethod" value="%AuthMethod%" />
            <input id="context" type="hidden" name="Context" value="%Context%" />
            <!-- End inputs are required by the presentation framework. -->
            <p id="pageIntroductionText">This content is provided by the MFA sample adapter. Challenge inputs should be presented below.</p>
            <label for="challengeQuestionInput" class="block">Question text</label>
            <input id="challengeQuestionInput" name="ChallengeQuestionAnswer" type="text" value="" class="text" placeholder="Answer placeholder" />
            <div id="submissionArea" class="submitMargin">
                <input id="submitButton" type="submit" name="Submit" value="Submit" onclick="return AuthPage.submitAnswer()"/>
            </div>
        </form>
        <div id="intro" class="groupMargin">
            <p id="supportEmail">Support information</p>
        </div>
        <script type="text/javascript" language="JavaScript">
            //<![CDATA[
            function AuthPage() { }
            AuthPage.submitAnswer = function () { return true; };
            //]]>
        </script>
    </div>
    
  14. 然後,選取 [專案新增>元件...資源 檔案和將檔案命名為 [資源],然後按兩下 [ 新增]:

    [新增專案] 對話框的螢幕快照,其中顯示已選取 [資源檔]。

  15. 然後,在 Resources.resx 檔案中,選擇 [新增資源...]新增現有檔案。 流覽至您上面儲存的文字檔(包含 html 片段)。

    請確保您的 GetFormHtml 程式碼能夠正確地透過資源檔(.resx 檔案)的名稱字首,解析出新資源的名稱,字首後需接上資源本身的名稱。

    public string GetFormHtml(int lcid)
    {
        string htmlTemplate = Resources.MfaFormHtml; //Resxfilename.resourcename
        return htmlTemplate;
    }
    

您現在應該能夠建置。

建置配接器

轉接器應該內建在強式名稱的 .NET 程式集中,可以安裝在 Windows 的 GAC 中。 若要在 Visual Studio 專案中達成此目的,請完成下列步驟:

  1. 在 [方案總管] 中以滑鼠右鍵按一下您的專案名稱,然後按一下 [屬性]。

  2. 在 [ 簽署 ] 索引標籤上,核取 [簽署元件 ],然後在 [選擇強式名稱金鑰檔案] 底下選擇 [新增...>]:<輸入金鑰檔名和密碼,然後按一下 [確定]。 然後確保已核取 簽署元件 且未核取 僅延遲簽署。 屬性 [簽署] 頁面看起來應該如下所示:

    建置提供者

  3. 然後構建解決方案。

將配接器部署至AD FS測試電腦

必須先在系統中註冊外部提供者,AD FS 才能叫用外部提供者。 配接器提供者必須提供安裝程式,以執行必要的安裝動作,包括 GAC 中的安裝,而且安裝程式必須支援 AD FS 中的註冊。 如果未完成,系統管理員必須執行下列 Windows PowerShell 步驟。 這些步驟可用於實驗室中,以啟用測試和偵錯。

準備測試AD FS 電腦

複製檔案並新增至 GAC。

  1. 請確定您有 Windows Server 2012 R2 計算機或虛擬機。

  2. 安裝 AD FS 角色服務,並使用至少一個節點設定伺服器群組。

    如需在實驗室環境中設定同盟伺服器的詳細步驟,請參閱 Windows Server 2012 R2 AD FS 部署指南

  3. 將 Gacutil.exe 工具複製到伺服器。

    Gacutil.exe 可以在 Windows 8 電腦上的 %homedrive%Program Files (x86) Microsoft SDKs Windows v8.0AbinNETFX 4.0 Tools 中找到。 您將需要 gacutil.exe 檔案本身,以及 1033en-US,以及 NETFX 4.0 工具 位置下方的其他當地語系化資源資料夾。

  4. 將您的提供者檔案 (一或多個強式名稱簽署 .dll 檔案) 複製到與 gacutil.exe 相同的資料夾位置 (該位置只是為了方便起見)

  5. 將您的 .dll 檔案新增至伺服器陣列中每個 AD FS 聯盟伺服器上的 GAC:

    範例:使用命令行工具 GACutil.exe 將 dll 新增至 GAC: C:>.gacutil.exe /if .<yourdllname>.dll

    若要檢視 GAC 中的項目:C:>.gacutil.exe /l <yourassemblyname>

在AD FS中註冊您的提供者

符合上述必要條件之後,請在同盟伺服器上開啟 Windows PowerShell 命令視窗,並輸入下列命令(請注意,如果您使用使用 Windows 內部資料庫的同盟伺服器數位,則必須在伺服器數位的主要同盟伺服器上執行這些命令):

  1. Register-AdfsAuthenticationProvider –TypeName YourTypeName –Name “AnyNameYouWish” [–ConfigurationFilePath (optional)]

    其中 YourTypeName 是您的 .NET 強型別名稱:“YourDefaultNamespace.YourIAuthenticationAdapterImplementationClassName,YourAssemblyName,Version=YourAssemblyVersion,Culture=neutral,PublicKeyToken=YourPublicKeyTokenValue,processorArchitecture=MSIL”

    這會在AD FS 中註冊您的外部提供者,其中包含您提供為AnyNameYouWish 上述的名稱。

  2. 重新啟動AD FS服務(例如,使用 Windows 服務嵌入式管理單元)。

  3. 執行下列命令:Get-AdfsAuthenticationProvider

    這會將您的提供者顯示為系統中的其中一個提供者。

    Example:

    $typeName = "MFAadapter.MyAdapter, MFAadapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e675eb33c62805a0, processorArchitecture=MSIL”
    Register-AdfsAuthenticationProvider -TypeName $typeName -Name “MyMFAAdapter”
    net stop adfssrv
    net start adfssrv
    

    如果您的 AD FS 環境中已啟用裝置註冊服務,也請執行下列 PowerShell 命令: net start drs

    若要驗證已註冊的提供者,請使用下列 PowerShell 命令:Get-AdfsAuthenticationProvider

    這會將您的提供者顯示為系統中的其中一個提供者。

建立會叫用您配接器的 AD FS 驗證原則

使用 AD FS 管理控制台附加元件建立身份驗證策略

  1. 開啟 AD FS 管理嵌入式管理單元 (從 [伺服器管理員 工具] 功能表)。

  2. 按一下 驗證原則

  3. 在中央窗格的 [多重要素驗證] 底下,按一下 [全域設定] 右側的 [編輯] 連結。

  4. 在頁面底部的 [ 選取其他驗證方法 ] 底下,核取提供者的 AdminName 方塊。 按一下 套用

  5. 例如,若要提供使用配接器叫用 MFA 的「觸發程式」,請在 [位置] 底下同時檢查 [外部網路] 和 [內部網路]。 按一下 [確定]。 (若要為每個信賴憑證者設定觸發程式,請參閱下方的<使用 Windows PowerShell 建立驗證原則>。

  6. 使用下列命令檢查結果:

    首先使用 Get-AdfsGlobalAuthenticationPolicy。 您應該會看到您的提供者名稱作為其中一個 AdditionalAuthenticationProvider 值。

    然後使用Get-AdfsAdditionalAuthenticationRule。 您應該會在管理員 UI 中看到由您的政策選擇所設定的外部網路和內部網路規則。

使用 Windows PowerShell 建立驗證原則

  1. 首先,在全域政策中啟用提供者:

    Set-AdfsGlobalAuthenticationPolicy -AdditionalAuthenticationProvider “YourAuthProviderName”`
    

    Note

    請注意,為 AdditionalAuthenticationProvider 參數提供的值會對應至您在上述 Register-AdfsAuthenticationProvider Cmdlet 中為 “Name” 參數提供的值,以及來自 Get-AdfsAuthenticationProvider Cmdlet 輸出的 “Name” 屬性。

    Set-AdfsGlobalAuthenticationPolicy –AdditionalAuthenticationProvider “MyMFAAdapter”`
    
  2. 接下來,設定全域或信任方的特定規則以觸發多因素驗證 (MFA):

    範例 1:若要建立全域規則以要求 MFA 於外部請求中:

    Set-AdfsAdditionalAuthenticationRule –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" );'
    

    範例 2:建立 MFA 規則,以要求對特定信賴方的外部請求進行 MFA。 (注意: 個別提供者無法連線到 Windows Server 2012 R2 中 AD FS 中的個別信賴憑證者)。

    $rp = Get-AdfsRelyingPartyTrust –Name <Relying Party Name>
    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 進行驗證

最後,執行下列步驟來測試您的配接器:

  1. 請確保 AD FS 的全域主要驗證類型設為表單驗證,適用於外部網路和內部網路(這可讓您的示範更容易以特定使用者身分進行驗證)

    1. 在 AD FS 嵌入式管理單元的 [驗證原則] 底下的 [主要驗證] 區域中,按一下 [全域設定] 旁的 [編輯]。

      1. 或者,只要按一下多重要素原則 UI 中的 [主要] 索引標籤。
  2. 請確定 [表單驗證] 是針對 [外部網路] 和 [內部網路] 驗證方法檢查的唯一選項。 按一下 [確定]

  3. 開啟 IDP 起始的登入 html 頁面 (https://< fsname>/adfs/ls/idpinitiatedsignon.htm),並以測試環境中的有效 AD 使用者身分登入。

  4. 輸入主要驗證的帳號憑證。

  5. 您應該會看到 MFA(多因素驗證)表單頁面,並且出現範例挑戰問題。

    如果您已設定多個配接器,您會看到 MFA 選擇頁面,上面有您易記的名稱。

    M F A 表單頁面的螢幕快照,其中包含範例挑戰問題。

    M F A 選擇頁面的螢幕快照。

您現在有介面的工作實作,而且您知道模型的運作方式。 您可以嘗試做為額外的範例,在 BeginAuthentication 和 TryEndAuthentication 中設定斷點。 當使用者第一次進入 MFA 表單時,執行 BeginAuthentication;而在每次提交表單時,觸發 TryEndAuthentication。

更新配接器以取得成功驗證

但等候 – 您的範例配接器永遠不會成功驗證! 這是因為您的程式碼中對於 TryEndAuthentication 沒有任何返回 null 的情況。

藉由完成上述程式,您已建立基本配接器實作,並將其新增至 AD FS 伺服器。 您可以取得 MFA 表單頁面,但尚未完成身份驗證,因為您尚未在 TryEndAuthentication 實作方法中放置正確的邏輯。 因此,讓我們新增它。

回想一下 TryEndAuthentication 實作:

public IAdapterPresentation TryEndAuthentication(IAuthenticationContext authContext, IProofData proofData, HttpListenerRequest request, out Claim[] outgoingClaims)
{
    //return new instance of IAdapterPresentationForm derived class
    outgoingClaims = new Claim[0];
    return new MyPresentationForm();
}

讓我們更新它,使其不一定會傳回 MyPresentationForm()。 為此,您可以在 類別內建立一個簡單的公用程式方法:

static bool ValidateProofData(IProofData proofData, IAuthenticationContext authContext)
{
    if (proofData == null || proofData.Properties == null || !proofData.Properties.ContainsKey("ChallengeQuestionAnswer"))
    {
        throw new ExternalAuthenticationException("Error - no answer found", authContext);
    }

    if ((string)proofData.Properties["ChallengeQuestionAnswer"] == "adfabric")
    {
        return true;
    }
    else
    {
        return false;
    }
}

然後,更新 TryEndAuthentication,如下所示:

public IAdapterPresentation TryEndAuthentication(IAuthenticationContext authContext, IProofData proofData, HttpListenerRequest request, out Claim[] outgoingClaims)
{
    outgoingClaims = new Claim[0];
    if (ValidateProofData(proofData, authContext))
    {
        //authn complete - return authn method
        outgoingClaims = new[]
        {
            // Return the required authentication method claim, indicating the particulate authentication method used.
            new Claim( "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod", "http://example.com/myauthenticationmethod1" )
        };
        return null;
    }
    else
    {
        //authentication not complete - return new instance of IAdapterPresentationForm derived class
        return new MyPresentationForm();
    }
}

現在您必須在測試方塊上更新配接器。 您必須先復原 AD FS 原則,然後從 AD FS 取消註冊並重新啟動 AD FS,然後從 GAC 移除 .dll,然後將新的 .dll 新增至 GAC,然後在 AD FS 中註冊、重新啟動 AD FS,然後重新設定 AD FS 原則。

在測試AD FS 電腦上部署和設定更新的配接器

清除 AD FS 策略

清除 MFA UI 中的所有 MFA 相關複選框,如下所示,然後按兩下 [確定]。

明確政策明確政策

取消註冊提供者 (Windows PowerShell)

PS C:> Unregister-AdfsAuthenticationProvider –Name “YourAuthProviderName”

例:PS C:> Unregister-AdfsAuthenticationProvider –Name “MyMFAAdapter”

您針對 「Name」 傳遞的值與您提供給 Register-AdfsAuthenticationProvider Cmdlet 的 「Name」 值相同。 它也是 Get-AdfsAuthenticationProvider 輸出的 “Name” 屬性。

取消註冊提供者之前,您必須先從 AdfsGlobalAuthenticationPolicy 移除提供者(可以透過在 AD FS 管理嵌入管理單元中取消選擇所選的複選框,或使用 Windows PowerShell 來完成)。

此作業之後必須重新啟動AD FS服務。

從 GAC 移除元件

  1. 首先,使用下列命令來尋找項目的完整強名稱:C:>.gacutil.exe /l <yourAdapterAssemblyName>

    例:C:>.gacutil.exe /l mfaadapter

  2. 然後,使用下列命令從 GAC 中移除它:.gacutil /u “<output from the above command>”

    例:C:>.gacutil /u “mfaadapter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e675eb33c62805a0, processorArchitecture=MSIL”

將更新的元件新增至 GAC

請務必先將更新的 .dll 貼到本地。 C:>.gacutil.exe /if .MFAAdapter.dll

在 GAC 中檢視元件(命令列)

C:> .gacutil.exe /l mfaadapter

在AD FS中註冊您的提供者

  1. PS C:>$typeName = "MFAadapter.MyAdapter, MFAadapter, Version=1.0.0.1, Culture=neutral, PublicKeyToken=e675eb33c62805a0, processorArchitecture=MSIL”

  2. PS C:>Register-AdfsAuthenticationProvider -TypeName $typeName -Name “MyMFAAdapter1”

  3. 重新啟動 AD FS 服務。

使用 AD FS 管理控制台附加元件建立身份驗證策略

  1. 開啟 AD FS 管理嵌入式管理單元 (從 [伺服器管理員 工具] 功能表)。

  2. 按一下 驗證原則

  3. 在多重要素驗證下,按一下全域設定右側的編輯連結。

  4. [選取其他驗證方法] 底下,勾選提供者 AdminName 選項的方塊。 按一下 套用

  5. 例如,若要提供使用配接器叫用 MFA 的「觸發程式」,請在 [位置] 底下同時檢查 [外部網路] 和 [內部網路]。 按一下 [確定]

使用配接器向 MFA 進行驗證

最後,執行下列步驟來測試您的配接器:

  1. 請確定 AD FS 全域主要驗證類型已設定為外部網路和內部網路的 表單驗證 (這可讓您更輕鬆地以特定使用者身分進行驗證)。

    1. 在 AD FS 管理嵌入式管理單元的 [驗證原則] 底下的 [主要驗證] 區域中,按一下 [全域設定] 旁的 [編輯]。

      1. 或者,只要按一下多重要素原則 UI 中的 [主要] 索引標籤。
  2. 請確定 [表單驗證] 是針對 [外部網路 ] 和 [內部網路] 驗證方法檢查的唯一選項。 按一下 [確定]

  3. 開啟 IDP 起始的登入 html 頁面 (https://< fsname>/adfs/ls/idpinitiatedsignon.htm),並以測試環境中的有效 AD 使用者身分登入。

  4. 請輸入主要驗證的憑證。

  5. 您應該會看到 MFA 表單頁面顯示範例挑戰文字。

    1. 如果您已設定多個配接器,您會看到 MFA 選擇頁面,其中包含您的易記名稱。

在 MFA 驗證頁面輸入 adfabric 時,您應該會看到登入成功。

M F A 表單頁面的螢幕快照,其中含有範例挑戰文字。

M F A 成功登入頁面的螢幕快照。

另請參閱

其他資源

其他驗證方法

使用敏感性應用程式的其他多重要素驗證來管理風險