private GraphServiceClient GetAppServiceClient()
        {
            if (_graphServiceAppClient != null)
            {
                return(_graphServiceAppClient);
            }
            _graphServiceAppClient = new GraphServiceClient(new DelegateAuthenticationProvider(
                                                                async requestMessage =>
            {
                // Passing tenant ID to the auth provider to use as a cache key
                var accessToken = await _authProvider.GetAppAccessTokenAsync();

                // Append the access token to the request
                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
            }));

            return(_graphServiceAppClient);
        }
        public GraphServiceClient GetAuthenticatedAppClient()
        {
            if (_graphServiceAppClient != null)
            {
                return(_graphServiceAppClient);
            }
            _graphServiceAppClient = new GraphServiceClient(new DelegateAuthenticationProvider(
                                                                async requestMessage =>
            {
                // Passing tenant ID to the auth provider to use as a cache key
                var accessToken = await _authProvider.GetAppAccessTokenAsync();

                // Append the access token to the request
                requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                // This header identifies the app in the Microsoft Graph service. If extracting this code for your project please remove.
                // requestMessage.Headers.Add("SomeID", "golocal-timetracker"
            }));

            return(_graphServiceAppClient);
        }
        public GraphClientAppContext(
            IGraphAuthProvider authProvider,
            IUserContext userContext)
        {
            _authProvider = authProvider ?? throw new ArgumentNullException(nameof(authProvider));
            _userContext  = userContext ?? throw new ArgumentNullException(nameof(userContext));

            // Initialize the graph client given the chosen context
            if (_graphServiceClient == null)
            {
                _graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(
                                                                 async requestMessage =>
                {
                    // Passing tenant ID to the auth provider to use as a cache key
                    var accessToken = await _authProvider.GetAppAccessTokenAsync();

                    // Append the access token to the request
                    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                }));
            }
        }