Mounhim
Mounhim

Reputation: 1724

Generate Short Code for Email Confirmation using Asp.Net Identity core 2.1

This requirement is posted somewhere else on SO, but the answer contained IUserTokenProvider which I cannot find in asp.net core 2.1.

How can I implement a emailconfirmation routine where the user does not click on a link but receives a short token (6 characters) that can safely be used to confirm the emailaddress.

Upvotes: 0

Views: 980

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239270

When you're configuring Identity, you can pass in a set of options, among which are token providers for various scenarios. There's a built-in EmailTokenProvider<TUser> that inherits from TotpSecurityStampBasedTokenProvider<TUser>. You can just use this. It's actually already registered via a call to AddDefaultTokenProviders(), which the AddIdentity<TUser, TRole> and AddDefaultIdentity<TUser> methods internally call. As a result, you can simply use TokenOptions.DefaultEmailProvider to set it to that provider:

services.AddDefaultIdentity<IdentityUser>(o => {
    // other options: password reqs, username reqs, etc.
    o.Tokens.EmailConfirmationTokenProvider = TokenOptions.DefaultEmailProvider;
});

Upvotes: 2

Related Questions