/// <summary>
        /// Login the user from Azure AD and Get Microsoft Graph access token.
        /// </summary>
        /// <remarks>Need Sign in and read user profile scopes (User.Read)</remarks>
        /// <returns>Returns success or failure of login attempt.</returns>
        public async Task <bool> LoginAsync()
        {
            _isConnected = false;
            if (!_isInitialized)
            {
                throw new InvalidOperationException("Microsoft Graph not initialized.");
            }

            _authentication = new MicrosoftGraphAuthenticationHelper();
            string accessToken = null;

            if (_authenticationModel == AuthenticationModel.V1)
            {
                accessToken = await _authentication.GetUserTokenAsync(_appClientId);
            }
            else
            {
                // accessToken = await _authentication.GetUserTokenV2Async(_appClientId);
            }

            if (string.IsNullOrEmpty(accessToken))
            {
                return(_isConnected);
            }

            _isConnected = true;

            _user = new MicrosoftGraphUserService(_graphProvider);

            if ((_servicesToInitialize & ServicesToInitialize.UserProfile) == ServicesToInitialize.UserProfile)
            {
                await GetUserAsyncProfile();
            }

            // if ((_servicesToInitialize & ServicesToInitialize.OneDrive) == ServicesToInitialize.OneDrive)
            // {
            //    _user.InitializeDrive();
            // }
            if ((_servicesToInitialize & ServicesToInitialize.Message) == ServicesToInitialize.Message)
            {
                _user.InitializeMessage();
            }

            if ((_servicesToInitialize & ServicesToInitialize.Event) == ServicesToInitialize.Event)
            {
                _user.InitializeEvent();
            }

            return(_isConnected);
        }
 /// <summary>
 /// Create Microsoft Graph client
 /// </summary>
 /// <param name='appClientId'>Azure AD's App client id</param>
 /// <returns>instance of the GraphServiceclient</returns>
 private GraphServiceClient CreateGraphClientProvider(string appClientId)
 {
     return(new GraphServiceClient(
                new DelegateAuthenticationProvider(
                    async(requestMessage) =>
     {
         // requestMessage.Headers.Add('outlook.timezone', 'Romance Standard Time');
         requestMessage.Headers.Authorization =
             new AuthenticationHeaderValue(
                 "bearer",
                 await _authentication.GetUserTokenAsync(appClientId).ConfigureAwait(false));
         return;
     })));
 }
        /// <summary>
        /// Login the user from Azure AD and Get Microsoft Graph access token.
        /// </summary>
        /// <remarks>Need Sign in and read user profile scopes (User.Read)</remarks>
        /// <returns>Returns success or failure of login attempt.</returns>
        public async Task <bool> LoginAsync()
        {
            _isConnected = false;
            if (!_isInitialized)
            {
                throw new InvalidOperationException("Microsoft Graph not initialized.");
            }

            _authentication = new MicrosoftGraphAuthenticationHelper();
            var accessToken = await _authentication.GetUserTokenAsync(_appClientId);

            if (string.IsNullOrEmpty(accessToken))
            {
                return(_isConnected);
            }

            _isConnected = true;

            await InitializeUserAsync();

            return(_isConnected);
        }