protected override void EndProcessing()
        {
            configuration = JsonConvert.DeserializeObject <WellKnownOpenIDConfiguration>(getAzureRegions());

            switch (AzureEnvironment)
            {
            case AzureEnvironment.AzureCloud:
            {
                endpoint = configuration.metadata[0].preferred_network;
                break;
            }

            case AzureEnvironment.AzureChinaCloud:
            {
                endpoint = configuration.metadata[1].preferred_network;
                break;
            }

            case AzureEnvironment.AzureGermanyCloud:
            {
                endpoint = configuration.metadata[2].preferred_network;
                break;
            }

            case AzureEnvironment.USGovernment:
            {
                endpoint = configuration.metadata[3].preferred_network;
                break;
            }

            default:
            {
                endpoint = configuration.metadata[0].preferred_network;
                break;
            }
            }

            HttpResponseMessage r;
            String result = getGrantTypePasswordAuthentication(endpoint, out r);

            //
            // needs to be reworked using events
            //
            if (r.IsSuccessStatusCode)
            {
                GlobalAuthToken.Auth = JsonConvert.DeserializeObject <BearerToken>(result);

                WriteObject(GlobalAuthToken.Auth);
                WriteVerbose("IsSuccessStatusCode -eq $true: Authentication successful.");
            }
            else
            {
                AuthError AE = JsonConvert.DeserializeObject <AuthError>(result);
                if (AE.error.Equals("interaction_required"))
                {
                    // implementation required
                    WriteVerbose("AE.error.Equals(interaction_required). Trying authentication using GrantType code.");
                    GlobalAuthToken.Auth = getGrantTypeCodeAuthentication(endpoint);
                    if (GlobalAuthToken.Auth.access_token.Length > 10)
                    {
                        WriteObject(GlobalAuthToken.Auth);
                        WriteVerbose("Authentication successful.");
                    }
                }
                else
                {
                    WriteObject(AE);
                    WriteVerbose("Authentication failed.");
                }
            }
        }