예제 #1
0
 private async Task <bool> TryAuthorize(string username, string password, HttpContext httpContext,
                                        ServiceIdentityList.ServiceAuthContext authContext)
 {
     GuardIsAjaxRequest(httpContext);
     GuardHasValidReferrer(httpContext);
     GuardHasValidOrigin(httpContext);
     authContext.ApiResource = ServiceAuthType.Api;
     return(await _pangulAuthService.TryAuthorize(username, password, authContext));
 }
예제 #2
0
        public async Task <StandardResponse> Login(HttpContext httpContext, LoginViewModel model, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                return(modelState.StandardError());
            }

            var authContext = new ServiceIdentityList.ServiceAuthContext();
            var isValid     = await TryAuthorize(model.Username, model.Password, httpContext, authContext);

            if (!isValid)
            {
                throw new Exception($"Invalid login attempt for {model.Username}");
            }

            await _auth.SignInAsync(httpContext, model.Username, authContext.ClaimsForUser);

            return(StandardResponse.ForSuccess());
        }