Mike Smith
Mike Smith

Reputation: 642

ASP Core Identity Claims - Claims That Become Out of Date

I'm developing a pretty standard membership type ASP Core MVC site using the out of the box Identity functionality with Claims. Upon login, I create various claims for "FirstName" etc... so I can easily call them on various pages that might need that value.

I want to create a claim called "SubscriptionEndDate" so I can determine if somebody has an authenticated login but their subscription has expired. I allow them to go to various areas with an expired subscription (ex. Renew Subscription page) but they can't do the main functionality of the site.

This all works fine until we hit the renewal date and their subscription is renewed (through another background process). Since I do allow them to save the Authentication cookie on their computer to bypass login, there is a time when the renewal happens but the SubscriptionEndDate Claim is out of date. So the site will give them a false error message that their account is expired. Bad.

I really just need to check the DB once upon each session start (ie. when they open a browser and go to my site again, even if they have saved their Authentication cookie). I'm sure this has been solved before - any suggestions?

Thanks!

Upvotes: 1

Views: 1293

Answers (1)

Deepak Mishra
Deepak Mishra

Reputation: 3183

You can do this using ValidatePrincipal Event, details are provided in the link.

https://learn.microsoft.com/en-us/aspnet/core/security/authentication/cookie?view=aspnetcore-3.1#react-to-back-end-changes

Upvotes: 1

Related Questions