Asp.NetCore Identity - Create custom token provider

10,290

https://www.stevejgordon.co.uk/asp-net-core-identity-token-providers

Read through the documentation, it's quite clear.

I simply had to add .AddTokenProvider<DataProtectorTokenProvider<Entity>>("purpose") to my services.AddIdentity<Entity, IdentityRole>() in start.cs

The ("purpose") can be anything you want it to be. I just needed it to validate some user input before making changes to the entity.

Share:
10,290

Related videos on Youtube

Haraldur
Author by

Haraldur

Updated on June 04, 2022

Comments

  • Haraldur
    Haraldur almost 2 years

    So I'm trying to create a custom token by using UserManager<TUser>.GenerateUserTokenAsync(TUser user, string tokenProvider, string purpose) method but I keep getting an error when I try to generate the token.

    I know the purpose can be just plain text declaring what the token is used for and needs to be the same when validating it later. So my guess is that the tokenProvider is the problem.

    After doing some research I got to the conclusion that I need to declare my own tokenProvider in Startup.cs but the information I found doesn't seem to work for me.

    Can anyone provide a bit of insight here on how to go about implementing a custom tokenProvider? And if my research is wrong, how do I make this work?

    • Haraldur
      Haraldur about 6 years
      Thank you for the info! Read through it and got the token provider up and running