private Task <OAuthAccessToken> GetTokenFromServiceAsync()
        {
            return(Task.Run(async() =>
            {
                int attempts = 0;

                OAuthAccessToken tempToken = null;
                while (tempToken == null)
                {
                    _logger.Debug($"Initial call to get a token: attempt {++attempts}");

                    var oneTimePassword = await GetOneTimePassword();
                    tempToken = await _executionPolicy.ExecuteAsync(async() =>
                                                                    await _tokenService.GetAccessToken(oneTimePassword));

                    if (tempToken == null)
                    {
                        _logger.Warn($"The attempt to get a token from HMRC failed - sleeping {_hmrcAuthTokenBrokerConfig.RetryDelay} and trying again");
                        await Task.Delay(_hmrcAuthTokenBrokerConfig.RetryDelay);
                    }
                }

                _cachedAccessToken = tempToken;

                return _cachedAccessToken;
            }));
        }
예제 #2
0
        private async Task <OAuthAccessToken> GetTokenFromService()
        {
            _logger.Debug("Attempting to get privileged access token from service");
            var secret = await _secretRepository.GetSecretAsync(PrivilegedAccessSecretName);

            var totp  = _totpService.Generate(secret);
            var token = await _tokenService.GetAccessToken(totp);

            _logger.Debug("Got privileged access token from service");
            return(token);
        }