Ejemplo n.º 1
0
        public async Task <IActionResult> GetJwt()
        {
            var apiKeyService = new ApiKeyService();
            var service       = apiKeyService.GetRandom();

            return(Ok(service.ApiKey));

            var claims = new List <Claim>();

            claims.Add(new Claim("UserId", "123"));

            var key         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("tosekret123dasdasd213das"));
            var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var jwtToken = new JwtSecurityToken(
                "http://localhost:59043",
                "http://localhost:59043",
                claims,
                expires: DateTime.Now.AddMinutes(60),
                signingCredentials: credentials
                );

            return(Ok(new JwtSecurityTokenHandler().WriteToken(jwtToken)));
        }