Adding refresh token support to the backend
We've covered enough theory for now, so let's crack on and see how refresh tokens actually work. We can't do anything on the frontend of the app until the backend supports refresh tokens, so that's where we're going to start.
Extending the AppUser model
First up, we need a place to store the refresh token as and when we generate it. As previously discussed, this token is unique to each user, so it belongs in our Data/Entities/AppUser
entity model:
namespaceECommerce.Data.Entities { publicclassAppUser : IdentityUser<int> { publicstring FirstName { get; set; } publicstring LastName { get; set; } publicstring RefreshToken { get; set; } [NotMapped] publicstring FullName { get { return$"{FirstName} {LastName}"; } } publicList<Order> Orders { get; set; } =newList<Order>(); } }
With this property in place, we also need to make sure it is unique. As this requires an index to be placed on the database...