Beispiel #1
0
        public IActionResult LoginAlumn([FromBody] LoginModel user)
        {
            LoginModel loginResponse = login.GetUserAlumn(user);

            if (loginResponse == null)
            {
                return(Ok(new { Token = "Unauthorized" }));
            }
            if (user.userName == loginResponse.userName && user.password == loginResponse.password)
            {
                var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("superSecretKey@345"));
                var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

                var tokeOptions = new JwtSecurityToken(
                    issuer: "http://localhost:44344",
                    audience: "http://localhost:44344",
                    claims: new List <Claim>(),
                    expires: DateTime.Now.AddMinutes(5),
                    signingCredentials: signinCredentials
                    );

                var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
                return(Ok(new { Token = tokenString, user = "******", userName = user.userName }));
            }
            else
            {
                return(Unauthorized());
            }
        }