Exemplo n.º 1
0
 public bool AddRefreshToken(RefreshToken token)
 {
     var exist = DatabaseService.Get(new IsRefreshTokenExist(token));
     try
     {
         DatabaseService.BeginTransaction();
         if (exist)
         {
             RemoveRefreshToken(token);
         }
         DatabaseService.Save(token);
         DatabaseService.CommitTransaction();
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
        public void Create(AuthenticationTokenCreateContext context)
        {
            var clientid = context.Ticket.Properties.Dictionary["as:client_id"];

            if (string.IsNullOrEmpty(clientid))
            {
                return;
            }

            var guid = Guid.NewGuid().ToString();

            // maybe only create a handle the first time, then re-use for same client
            var refreshToken = Crypto.Hash(guid);


            var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");

            var token = new RefreshToken()
            {
                Id = refreshToken,
                ClientId = clientid,
                Subject = context.Ticket.Identity.Name,
                IssuedUtc = DateTime.UtcNow,
                ExpiresUtc = DateTime.UtcNow.AddSeconds(Convert.ToDouble(refreshTokenLifeTime))
            };

            context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
            context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;

            token.ProtectedTicket = context.SerializeTicket();
            var result = AuthenticationService.AddRefreshToken(token);

            if (result)
            {
                context.SetToken(refreshToken);
            }
        }
Exemplo n.º 3
0
 public bool RemoveRefreshToken(RefreshToken refreshToken)
 {
     try
     {
         DatabaseService.Delete(refreshToken);
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }