예제 #1
0
        public ActionResult <string> SignIn(LoginViewModel login)
        {
            // 以下變數值應該透過 IConfiguration 取得
            var issuer  = _configuration["JWT:issuser"].ToString();       //"JwtAuthDemo";
            var signKey = _configuration["JWT:signKey"].ToString();       // 請換成至少 16 字元以上的安全亂碼
            var expires = Convert.ToInt32(_configuration["JWT:expires"]); // 單位: 分鐘

            if (_userValidateService.ValidateUser(login))
            {
                return(JwtHelpers.GenerateToken(issuer, signKey, login.Username, expires, _userInfoService.GetApiRoles(login.Username), JsonConvert.SerializeObject(_userInfoService.GetUserInfo(login.Username))));
            }
            else
            {
                return(BadRequest());
            }
        }