Windows Server 2012 中建立 AD FS 的自訂驗證方法

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

警告

您在這裡建立的範例僅供教育之用。  這些指示是揭露模型所需元素的最簡單、最少的實作步驟。  其中不包含驗證後端、錯誤處理或組態資料。

設定開發方塊

此逐步解說會使用 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 為目標。

    Screenshot of the New Project dialog box showing the Class Library option selected.

  3. 在安裝 AD FS 的 Windows Server 2012 R2 伺服器上,複製 %windir%\ADFS 的 Microsoft.IdentityServer.Web.dll,並將其貼上至開發電腦上的專案資料夾中。

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

  5. 瀏覽至 Microsoft.IdentityServer.Web.dll 的本機複本,並按一下 [新增...]

  6. 按一下 [確定] 以確認新的參考:

    Screenshot of the Reference Manager dialog box showing the Microsoft.IdentityServer.Web.dll selected.

    您現在已經設定完成,可解析提供者所需的所有類型。

  7. 將新類別新增至專案 (以滑鼠右鍵按一下您的專案、新增...類別...),並命名為 MyAdapter,如下所示:

    Screenshot of the Add New Item dialog box with the Class option selected.

  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 元素的「todo」。 您可以在一分鐘內將其修正,但首先讓我們根據新實作的類型,將最後所需的 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. 然後,選取 [專案]->[新增元件...][資源] 檔案,並將檔案命名為 Resources,然後按一下 [新增:]

    Screenshot of the Add New Item dialog box showing Resource File selected.

  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. 在 [簽署] 索引標籤上,勾選 [簽署組件],然後選擇 [選擇強式名稱金鑰檔:] 下方的 [<新增...>],輸入金鑰檔案名稱和密碼,然後按一下 [確定]。 接著確認已勾選 [簽署組件],且 [僅延遲簽署] 為未勾選狀態。 [簽署] 屬性頁面看起來應該像這樣:

    build the provider

  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 SDKsWindowsv8.0AbinNETFX 4.0 Tools 中找到。 您將需要 gacutil.exe 檔案本身和 1033en-US,以及 NETFX 4.0 Tools 位置下的其他當地語系化資源資料夾。

  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

    如此一來,您的提供者便顯示為系統中的其中一個提供者。

    範例:

    $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”`
    

    注意

    請注意,為 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 選擇頁面,上面有您的自訂名稱。

    Screenshot of the the M F A forms page with example challenge questions.

    Screenshot of the the M F A choice page.

現在您已完成介面的實作,並且知道模型的運作方式。 做為額外的範例,您可以嘗試在 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 相關核取方塊,如下所示,然後按一下 [確定]。

clear policy

取消註冊提供者 (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 時,您應該會看到登入成功。

Screenshot of the M F A forms page with example challenge text.

Screenshot of the M F A successful sign in page.

另請參閱

其他資源

其他驗證方法

透過其他多重要素驗證管理機密應用程式的風險