Пример #1
0
        private static TokenWrapper ConvertToInternalToken(string response)
        {
            var authTokenResponse = JsonConvert.DeserializeObject <AuthTokenResponse>(response);
            var token             = new TokenWrapper
            {
                Expiry      = DateTimeOffset.Now.Add(TimeSpan.FromSeconds(authTokenResponse.ExpiresIn)),
                AccessToken = authTokenResponse.AccessToken
            };

            return(token);
        }
Пример #2
0
        private async Task EnsureAccessToken()
        {
            if (DateTimeOffset.Now > _tokenWrapper.Expiry.GetValueOrDefault())
            {
                await _accessTokenSemaphore.WaitAsync();

                try
                {
                    if (DateTimeOffset.Now > _tokenWrapper.Expiry.GetValueOrDefault())
                    {
                        _tokenWrapper = await _authProvider.GetAccessTokenAsync(GraphLiteConfiguration.AzureADGraphApiRoot);
                    }
                }
                finally
                {
                    _accessTokenSemaphore.Release();
                }
            }
        }