What is the use of id asp.net.GenerateUserToken ()

I understand that the token from userManager.GeneratePasswordResetToken () is used to add as a security id in the hyperlink to send the reset password to the user.

But I'm not sure if the user is userManager.GenerateUserToken (). I can generate a token, but not sure if this can be converted to claims like SAML tokens and used for authorization.

Please help me understand this as I couldn't find good documentation on this.

+3


source to share


1 answer


GenerateUserToken()

used to generate reset tokens and email confirmation tokens. This method takes a string parameter purpose

that describes what operation will be performed. Effectively this purpose

is the encryption key that is used to decrypt the generated token.

So, you can create your own tokens for your own purposes, for example, you can have an ConfirmJobOffer

operation in a dialing application. And you can create a token just for this operation and send a link with this token to the user:

var token = userManager.GenerateUserToken(userId, "ConfirmJobOffer");
// now send this token as part of the link

      

Then in the controller, after the marker has done it back to you, you can call:



var tokenCorrect = await userManager.VerifyUserTokenAsync(userId, "ConfirmJobOffer", token);
if (tokenCorrect)
{
    // do stuff if token is correct
}

      

Typically, you will not use GenerateUserToken

directly, unless you are doing custom tokens. You must use GeneratePasswordResetTokenAsync

and GenerateEmailConfirmationTokenAsync

.

Please note: This does not target SAML tokens or their associated authorizations.

+10


source







All Articles