How to renew the token after each request (I use WebApi bearer token)

Problem:

  • I have ASP WebApi 2 with a standard Asp identifier (media)
  • Client platforms - Ios, Android, WinPhone and Web

The validity period of Ios, Android, WinPhone should be 1 year, but for the Web - 5 minutes, and the validity period should be extended after each user activity.

Each request may contain PlatformType (or other information)

How to extend the token after each user activity?

+4
source share
1 answer

, . .

RefreshTokenProvider = new AuthenticationTokenProvider()
            {
                OnCreate = (obj) =>
                {
                    obj.Ticket.Properties.ExpiresUtc = DateTime.UtcNow.AddMonths(6);
                    obj.SetToken(obj.SerializeTicket());
                },
                OnReceive = (obj) => { obj.DeserializeTicket(obj.Token); }
            },
+1

All Articles