Skip to content

Azure US Gov, Delegated auth, null ref exception. #39

@drdenson

Description

@drdenson

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
            };

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions