Ejemplo n.º 1
0
        public IActionResult Auth([FromBody] AuthorizeInputModel auth)
        {
            ClaimsIdentity identity = GetIdentity(auth.Login, auth.Password, auth.Role);

            if (identity != null)
            {
                DateTime         now = DateTime.UtcNow;
                JwtSecurityToken jwt = new JwtSecurityToken(
                    issuer: Models.TokenOptions.ISSUER,
                    audience: Models.TokenOptions.AUDIENCE,
                    notBefore: now,
                    claims: identity.Claims,
                    expires: now.Add(TimeSpan.FromMinutes(Models.TokenOptions.LIFETIME)),
                    signingCredentials: new SigningCredentials(Models.TokenOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)
                    );

                var response = new
                {
                    access_token = new JwtSecurityTokenHandler().WriteToken(jwt),
                    login        = auth.Login
                };
                return(Ok(response));
            }
            else
            {
                return(BadRequest("Введена неверная пара логин-пароль"));
            }
        }
Ejemplo n.º 2
0
        public async ValueTask <IActionResult> Authorization([FromBody] AuthorizeInputModel auth)
        {
            ClaimsIdentity identity = await GetIdentity(auth.Login, auth.Password);

            if (identity != null)
            {
                DateTime         now = DateTime.UtcNow;
                JwtSecurityToken jwt = new JwtSecurityToken(
                    issuer: Models.TokenOptions.ISSUER,
                    audience: Models.TokenOptions.AUDIENCE,
                    notBefore: now,
                    claims: identity.Claims,
                    expires: now.Add(TimeSpan.FromMinutes(Models.TokenOptions.LIFETIME)),
                    signingCredentials: new SigningCredentials(Models.TokenOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)
                    );
                var response = new
                {
                    access_token = new JwtSecurityTokenHandler().WriteToken(jwt),
                    login        = auth.Login
                };
                return(Ok(response));
            }
            else
            {
                return(BadRequest("Invalid login-password pair entered"));
            }
        }
Ejemplo n.º 3
0
        public UserWithLoginOutputModel Get([FromBody] AuthorizeInputModel log)
        {
            Mapper mapper = new Mapper();

            return(mapper.ConvertUserByLoginDTOToListUserWithLoginOutputModel(log.Login));
        }