public override void Receive(AuthenticationTokenReceiveContext context)
        {
            GrantData grantData = new GrantData()
            {
                Token = context.Token
            };

            if (RemoveWhenReceive)
            {
                TicketManage.RemoveTicketValue(ref grantData);
                context.DeserializeTicket(grantData.Ticket);
            }
            else
            {
                TicketManage.GetTicketValue(ref grantData);
                context.DeserializeTicket(grantData.Ticket);
            }
            context.OwinContext.Set("as:user_id", grantData.UserID);
            context.OwinContext.Set("as:user_name", grantData.UserName);
            context.OwinContext.Set("as:client_id", grantData.ClientID);
        }
        public override void Create(AuthenticationTokenCreateContext context)
        {
            var       startDate = DateTime.UtcNow;
            var       endDate   = DateTime.UtcNow.AddMinutes(GetExpiryMinutes());
            GrantData grantData = new GrantData
            {
                GrantType    = context.OwinContext.Get <string>("as:grant_type"),
                ResponseType = context.OwinContext.Get <string>("as:response_type"),
                TokenType    = TokenType,
                UserID       = context.OwinContext.Get <string>("as:user_id"),
                UserName     = context.OwinContext.Get <string>("as:user_name"),
                ClientID     = context.OwinContext.Get <string>("as:client_id"),
                IssuedUtc    = startDate,
                ExpiresUtc   = endDate,
                RoleScope    = GetIdentityRole(context.Ticket.Identity)
            };
            string tokenValue;

            if (TokenKeepingPredicate(grantData))
            {
                if (TicketManage.GetToken(grantData))
                {
                    context.SetToken(grantData.Token);
                    return;
                }
            }
            if (OldTokenRemovetPredicate(grantData))
            {
                TicketManage.RemoveOldTicket(grantData);
            }
            tokenValue = Convert.ToBase64String(Encoding.Default.GetBytes(Guid.NewGuid().ToString("n"))).TrimEnd('=').Replace('+', '-').Replace('/', '_');
            context.Ticket.Properties.IssuedUtc  = startDate;
            context.Ticket.Properties.ExpiresUtc = endDate;
            grantData.Ticket = context.SerializeTicket();
            grantData.Token  = tokenValue;
            TicketManage.SetTicketValue(grantData);
            context.SetToken(tokenValue);
        }