Beispiel #1
0
        // Only API call
        public async Task <AuthorizationResponse> LoginWithPasswordAsync(PasswordSignInModel parameters)
        {
            try
            {
                var user = await GetUserByEmailAsync(parameters.Email);

                var result = await _signInManager.PasswordSignInAsync(parameters.Email, parameters.Password, parameters.RememberMe, lockoutOnFailure : true);

                if (result.Succeeded)
                {
                    return(AuthorizationResponse.Success(user));
                }

                if (result.RequiresTwoFactor)
                {
                    return(AuthorizationResponse.TwoFactorRequired(user));
                }

                if (result.IsLockedOut)
                {
                    return(AuthorizationResponse.LockedOut(user));
                }

                return(AuthorizationResponse.Error(HESCode.InvalidLoginAttempt));
            }
            catch (HESException ex)
            {
                return(AuthorizationResponse.Error(ex.Code));
            }
            catch (Exception ex)
            {
                return(AuthorizationResponse.Error(ex.Message));
            }
        }
Beispiel #2
0
        public async Task <AuthorizationResponse> LoginWithPasswordAsync(PasswordSignInModel parameters)
        {
            var stringContent = new StringContent(JsonConvert.SerializeObject(parameters), Encoding.UTF8, "application/json");
            var httpResponse  = await _httpClient.PostAsync("api/Identity/LoginWithPassword", stringContent);

            var authorizationResponse = JsonConvert.DeserializeObject <AuthorizationResponse>(await httpResponse.Content.ReadAsStringAsync());

            await TrySetCookieAsync(httpResponse);

            if (authorizationResponse.Succeeded)
            {
                await SetAuthenticatedAsync(authorizationResponse.User);
            }

            return(authorizationResponse);
        }
Beispiel #3
0
 public async Task <AuthorizationResponse> LoginWithPassword(PasswordSignInModel parameters)
 {
     return(await _applicationUserService.LoginWithPasswordAsync(parameters));
 }