Exemplo n.º 1
0
        public void SignInViaCookies(LoggedClaims loggedClaims, bool isPersistent)
        {
            var identity = new ClaimsIdentity(loggedClaims.GetAsClaims(), CookieAuthenticationDefaults.AuthenticationScheme);

            _contextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)
                                                     , new AuthenticationProperties()
            {
                IsPersistent = isPersistent
            })
            .Wait();
        }
Exemplo n.º 2
0
        public string GenerateToken(LoggedClaims loggedClaims, DateTime?expires)
        {
            var handler = new JwtSecurityTokenHandler();

            var identity   = new ClaimsIdentity(loggedClaims.GetAsClaims(), JwtBearerDefaults.AuthenticationScheme);
            var descriptor = new SecurityTokenDescriptor
            {
                Issuer             = _tokenAuthOptions.Issuer,
                Audience           = _tokenAuthOptions.Audience,
                SigningCredentials = _tokenAuthOptions.SigningCredentials,
                Subject            = identity,
                Expires            = expires
            };

            var securityToken = handler.CreateToken(descriptor);

            return(handler.WriteToken(securityToken));
        }