Exemplo n.º 1
0
        public async Task CreateAsync(AuthenticationTokenCreateContext context)
        {
            var clientid = context.Ticket.Properties.Dictionary["client_id"];

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

            var refreshTokenId = Guid.NewGuid().ToString("n");


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

            var token = new RefreshToken()
            {
                RefreshTokensId = refreshTokenId,
                ClientId        = clientid,
                Subject         = context.Ticket.Identity.Name,
                IssuedAt        = DateTime.UtcNow,
                ExpiresAt       = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
            };

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

            token.ProtectedTicket = context.SerializeTicket();
            RefreshTokenService refreshTokenService = new RefreshTokenService();
            var result = await refreshTokenService.AddRefreshToken(token);

            if (result.Success)
            {
                context.SetToken(refreshTokenId);
            }
        }
Exemplo n.º 2
0
 public async Task <bool> AddRefreshToken(RefreshToken token)
 => await _refreshTokenService.AddRefreshToken(token);