示例#1
0
        public AuthorizeModel UpdateToken(string refreshToken)
        {
            AuthorizeModel token = _tokens.Find(at => at.RefreshToken == refreshToken);

            if (token == null || token.RefreshExpires <= DateTime.Now)
            {
                return(null);
            }

            Domain.Models.AccountView acc = _service.GetById(token.AccountId);

            if (acc == null)
            {
                return(null);
            }

            return(Authentication(acc));
        }
示例#2
0
        public AuthorizeModel Authentication(Domain.Models.AccountView acc)
        {
            List <Claim> claims = new List <Claim>()
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, acc.UserName),
                new Claim(ClaimsIdentity.DefaultRoleClaimType, acc.Role),
                new Claim("id", acc.Id.ToString())
            };
            ClaimsIdentity identity = new ClaimsIdentity(
                claims,
                "Token",
                ClaimsIdentity.DefaultNameClaimType,
                ClaimsIdentity.DefaultRoleClaimType);

            AuthorizeModel model = new AuthorizeModel()
            {
                AccountId      = acc.Id,
                AccessToken    = _jwt.GetJwt(identity),
                RefreshToken   = Guid.NewGuid().ToString(),
                RefreshExpires = DateTime.Now.AddMinutes(_settings.Value.RefreshLifetime)
            };

            return(model);
        }