private async Task AuthenticateToTooGoodToGoServices()
        {
            _logger.LogInformation("TooGoodToGoNotifier isn't authenticated, authenticating to TooGoodToGo's services");

            AuthenticateByEmailResponse authenticateByEmailResponse = await _tooGoodToGoService.AuthenticateByEmailAsync();

            int pollingAttempts = 0;
            AuthenticateByPollingIdResponse authenticateByPollingIdResponse;

            while (true)
            {
                pollingAttempts++;
                _logger.LogInformation("PollingId request attempt n°{pollingAttempts}", pollingAttempts);

                authenticateByPollingIdResponse = await _tooGoodToGoService.AuhenticateByPollingIdAsync(authenticateByEmailResponse.PollingId);

                if (authenticateByPollingIdResponse != null)
                {
                    _context.AccessToken  = authenticateByPollingIdResponse.AccessToken;
                    _context.RefreshToken = authenticateByPollingIdResponse.RefreshToken;
                    _context.UserId       = authenticateByPollingIdResponse.StartupData.User.UserId;
                    break;
                }

                await Task.Delay(TimeSpan.FromSeconds(15));
            }

            _logger.LogInformation("Ended authenticating to TooGoodToGo's services");
        }
Esempio n. 2
0
        public async Task <AuthenticateByEmailResponse> AuthenticateByEmailAsync()
        {
            var request = new HttpRequestMessage(HttpMethod.Post, $"{_apiOptions.BaseUrl}{_apiOptions.AuthenticateByEmailEndpoint}");

            var authenticateByEmailRequest = new AuthenticateByEmailRequest
            {
                DeviceType = "ANDROID",
                Email      = _apiOptions.AccountEmail
            };

            SerializeHttpRequestContentAsJson(request, authenticateByEmailRequest);

            AuthenticateByEmailResponse authenticateByEmailResponse = await ExecuteAndThrowIfNotSuccessfulAsync <AuthenticateByEmailResponse>(request);

            return(authenticateByEmailResponse);
        }