Пример #1
0
        static async Task <TokensResponse> AuthenticationMenu(ITesonetApi api)
        {
            TokensResponse        token       = null;
            CredentialsPayload    credentials = null;
            AuthenticationManager authManager = new AuthenticationManager(api);

            while (token == null)
            {
                credentials = UserInterface.AskForCredentials();

                token = await authManager.GetTokenAsync(credentials);

                if (token == null)
                {
                    UserInterface.InformAboutAuthorizationFailure();

                    if (UserInterface.AskIfExit())
                    {
                        break;
                    }
                }
            }

            return(token);
        }
Пример #2
0
        public async Task <TokensResponse> GetTokenAsync(CredentialsPayload credentials)
        {
            TokensResponse      token    = null;
            HttpResponseMessage response = await api.PostTokensAsync(credentials);

            if (response.IsSuccessStatusCode)
            {
                token = await response.Content.ReadAsAsync <TokensResponse>();

                logger.Info("Authentication successful. Status code: {0}", (int)response.StatusCode);
            }
            else
            {
                logger.Error("Authentication is not successful. Status code: {0}", (int)response.StatusCode);
            }

            return(token);
        }