示例#1
0
        public async Task CreateAsync(AuthenticationTokenCreateContext context)
        {
            var loginid = context.Ticket.Properties.Dictionary["as:login_id"];

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

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

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

            var token = new Domain.Tokens.Token()
            {
                Id         = HashEncryption.GetHash(refreshTokenId),
                Subject    = context.Ticket.Identity.Name,
                IssuedUtc  = DateTime.UtcNow,
                ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
            };

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

            token.ProtectedTicket = context.SerializeTicket();



            context.SetToken(refreshTokenId);
        }
示例#2
0
        public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
        {
            var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin");

            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });

            string hashedTokenId = HashEncryption.GetHash(context.Token);


            //var refreshToken = await _repo.FindRefreshToken(hashedTokenId);

            //if (refreshToken != null)
            //{
            //    //Get protectedTicket from refreshToken class
            //    context.DeserializeTicket(refreshToken.ProtectedTicket);
            //    var result = await _repo.RemoveRefreshToken(hashedTokenId);

            //}
        }