Ejemplo n.º 1
0
        public async Task <bool> LoginAsync(LoginUser model)
        {
            WriteLine("Starting Authentication process!");

            var response = await http
                           .Request("api", "auth", "token")
                           .PostUrlEncodedAsync(new
            {
                grant_type = "password",
                @for       = "Business",
                username   = model.Email,
                password   = model.Password,
            });

            if (!response.IsSuccessStatusCode)
            {
                WriteLine("Authentication failed!");
                return(false);
            }

            var authToken = DeserializeObject <AuthToken>(await response.Content.ReadAsStringAsync());

            await auth.MarkUserAsAuthenticated(authToken);

            WriteLine("Authentication succeeded!");
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <LoginResult> Login(LoginModel loginModel)
        {
            var response = await _httpClient.PostAsJsonAsync("api/login", loginModel);

            var loginResult = await response.Content.ReadFromJsonAsync <LoginResult>();

            if (!response.IsSuccessStatusCode)
            {
                return(loginResult);
            }

            await _localStorage.SetItemAsync("authToken", loginResult.Token);

            _authenticationStateProvider.MarkUserAsAuthenticated(loginModel.Email);
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", loginResult.Token);

            return(loginResult);
        }
Ejemplo n.º 3
0
        public async Task Login(LoginView model)
        {
            var token = await _httpClientService.PostJsonAsync <TokenView>(_apiOptions.Login, model);

            await _apiAuthenticationState.MarkUserAsAuthenticated(token.Token);
        }