/// <summary>
        /// Performs OAuth 2.0 authorization.
        /// Opens a window with browser control to make it possible for users to supply their username and password to Microsoft's authentication servers.
        /// </summary>
        public Task <OAuthAzureCredentials> AuthorizeAsync()
        {
            if (ClientId == null)
            {
                throw new InvalidOperationException("ClientId not specified.");
            }

            if (TenantId == null)
            {
                throw new InvalidOperationException("TenantId not specified.");
            }

            if (Scopes == null)
            {
                throw new InvalidOperationException("Scopes not specified.");
            }

            if (_credentials != null)
            {
                throw new InvalidOperationException("Only one authentication request can be performed.");
            }

            // get redirect URI and determine expected authority
            string redirectUri = RedirectUri ?? OAuthAzureCredentials.DefaultRedirectUri;

            // create an instance of OAuthAzureCredentials helper class
            _credentials = new OAuthAzureCredentials(ClientId, TenantId, PromptType, redirectUri, Scopes);

            // create task completion source for the whole action
            _taskCompletion = new TaskCompletionSource <OAuthAzureCredentials>();

            // Direct the user to authorization endpoint.
            // Once completed, the application will receive an authorization code.

            // show the window and navigate to authentication URI
            Show();
            webBrowser.Navigate(_credentials.AuthorizationUri);

            // return task that will finish on succcess or failure
            return(_taskCompletion.Task);
        }
        /// <summary>
        /// Performs OAuth 2.0 authorization.
        /// Opens a window with browser control to make it possible for users to supply their username and password to Microsoft's authentication servers.
        /// </summary>
        public void Authorize()
        {
            if (ClientId == null)
            {
                throw new InvalidOperationException("ClientId not specified.");
            }

            if (TenantId == null)
            {
                throw new InvalidOperationException("TenantId not specified.");
            }

            if (Scopes == null)
            {
                throw new InvalidOperationException("Scopes not specified.");
            }

            if (Credentials != null)
            {
                throw new InvalidOperationException("Only one authentication request can be performed.");
            }

            // get redirect URI and determine expected authority
            string redirectUri = RedirectUri ?? OAuthAzureCredentials.DefaultRedirectUri;

            // create an instance of OAuthAzureCredentials helper class
            Credentials = new OAuthAzureCredentials(ClientId, TenantId, PromptType, redirectUri, Scopes);

            // set field that indicates that authentication is in progress
            _authenticating = true;

            // Direct the user to authorization endpoint.
            // Once completed, the application will receive an authorization code.

            // show the window and navigate to authentication URI
            Show();
            webBrowser.Navigate(new Uri(Credentials.AuthorizationUri));
        }