Share via

Error on Initialize <Custom Authentication Method for AD FS in Windows Server >

Ehsan Rabiee 1 Reputation point
2021-05-22T14:59:58.81+00:00

I developed the c# DLL for customize AD FS MFA. So I use from this tutorial Build a Custom Authentication Method for AD FS in Windows Server

I use this Power Shell commands:

Set-Location "C:\Release"  
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")  
$publish = New-Object System.EnterpriseServices.Internal.Publish  
$publish.GacInstall("C:\Release\MFAAdapter.dll")  
([System.Reflection.Assembly]::LoadFile("C:\Release\MFAAdapter.dll")).FullName  
$typeName = "MFAAdapter.Adapter, MFAAdapter, Version=1.0.0.7, Culture=neutral, PublicKeyToken=23251ce4dd11647e, processorArchitecture=MSIL”  
Register-AdfsAuthenticationProvider -TypeName $typeName -Name “MFA Adapter” -ConfigurationFilePath 'C:\Release\config.json'  
net stop adfssrv  
net start adfssrv  

But after start ADFS service on event viewer this error occurs:

An error occurred loading an authentication provider. Fix configuration errors using PowerShell   

cmdlets and restart the Federation Service.   
Identifier: MFA Adapter   
Context: Proxy device TLS pipeline   
  
Additional Data   
Exception details:   
An error occurred initializing the 'MFA Adapter' authentication provider.  

But my DLL is load and work on Authentication. also it loads TryEndAuthentication() function

Why does this error occur?

At the end: There is another problem in calling the OnAuthenticationPipelineLoad() function. In this way, this function is not called at all and does not load the configuration file(config.json).

public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configData)  
    {  
        try  
        {  
            if (configData != null || configData.Data != null)  
            {  
                using (StreamReader reader = new StreamReader(configData.Data, Encoding.UTF8))  
                {  
                    var config = reader.ReadToEnd();  
                    var obj = JObject.Parse(config);  
                    EventLog.WriteEntry(  
                        "Application",  
                        String.Format("Config loaded for user:{0}. iKey:{1}, user_name, bj["ikey"]]),  
                        EventLogEntryType.Information);  

                    var ikey = obj["ikey"].ToString();  
                }  
            }  
            else  
            {  
                EventLog.WriteEntry(  
                            "Application",  
                            String.Format("Error: configData is null for user:{0}", user_name),  
                            EventLogEntryType.Error);  
                throw new ArgumentNullException();  
            }  
        }  
        catch (Exception ex)  
        {  
            EventLog.WriteEntry(  
                "Application",  
                String.Format("Exception on OnAuthenticationPipelineLoad for user:{0}: {1}", user_name, ex.Message),  
                EventLogEntryType.Error);  
            throw new ArgumentException(ex.Message);  
        }  
    }
Microsoft Security | Active Directory Federation Services
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Duane Arnold 3,216 Reputation points
    2021-05-23T12:01:45.22+00:00

    @Ehsan Rabiee
    Maybe, the link will help you. Nine times out of ten, someone has encountered the error. So yo you can take the error message and search Bing or Google for a possible resolution.

    https://social.technet.microsoft.com/Forums/en-US/2188b2a7-4ce6-4541-bce8-9bce2ca666eb/an-error-occurred-loading-an-authentication-provider?forum=ADFS

    HTH

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.