示例#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("Введена неверная пара логин-пароль"));
            }
        }
示例#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"));
            }
        }
示例#3
0
        public UserWithLoginOutputModel Get([FromBody] AuthorizeInputModel log)
        {
            Mapper mapper = new Mapper();

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