Ejemplo n.º 1
0
        public async Task <Token> LogIn(IUserAuthenticator authenticator)
        {
            await _authClient.AuthenticationRequest(HttpMethod.Get);

            if (User.Username == null && User.Password == null)
            {
                var credentials = await authenticator.OnLogInChallenge();

                User.Username = credentials.Item1;
                User.Password = credentials.Item2;
            }

            // User requested to cancel login process
            if (User.Username == null && User.Password == null)
            {
                User.Username = null;
                User.Password = null;
                return(null);
            }

            if (await _authClient.LogInRequest(User) == null)
            {
                User.Username = null;
                User.Password = null;
                return(null);
            }

            if (await authenticator.OnAppAuthorizeChallenge())
            {
                await _authClient.AuthenticationRequest(HttpMethod.Post);

                UpdateAuthenticationInfo(_authClient.ObtainedToken);
            }
            else
            {
                User.Username = null;
                User.Password = null;
                return(null);
            }

            authenticator.OnLogIn(User.Username, User.Password);
            return(User.AccessToken);
        }