EwsEditor icon indicating copy to clipboard operation
EwsEditor copied to clipboard

Azure US Gov, Delegated auth, null ref exception.

Open drdenson opened this issue 1 year ago • 0 comments

Hi, testing delegated authentication with a GCCH/DOD account is failing with a null ref exception when creating the service obj. Debug shows the failure in the oAuthHelper class - seems as tho MSAL doesn't like the PCA object created with the default/global authority and trying to use that for non-global auth flows. I worked up a quick switch statement to take the authority string and map that to the enum used in the PCA options object so that we create the PCA object with the correct authority from the beginning.

oAuthHelper.cs (inject @ LINE 92):

        //Initialize the cloudInstance enum.
        var OAuth2AzCloudInstance = AzureCloudInstance.None;

        //Switch to set logon authority enum.
        switch (OAuth2Authority)
        {
            case "https://login.microsoftonline.us":
                OAuth2AzCloudInstance = AzureCloudInstance.AzureUsGovernment;
                break;

            case "https://login.microsoftonline.de":
                OAuth2AzCloudInstance = AzureCloudInstance.AzureGermany;
                break;

            case "https://login.partner.microsoftonline.cn":
                OAuth2AzCloudInstance = AzureCloudInstance.AzureChina;
                break;
            default:
                OAuth2AzCloudInstance = AzureCloudInstance.AzurePublic;
                break;
        }

        if (OAuth2RedirectUrl != "<Do not use a redirect URL.>")
        {
            // Configure the MSAL client to get tokens
            pcaOptions = new PublicClientApplicationOptions
            {
                ClientId = ClientId,
                TenantId = TenantId,
                RedirectUri = OAuth2RedirectUrl,
                AzureCloudInstance = OAuth2AzCloudInstance
            };

drdenson avatar Apr 04 '23 19:04 drdenson