How to confirm a phone number in ASP.Net Core 1.1MVC

Viewed 7926

I cannot figure out how to do a phone number confirmation in asp.net core 1.1

Identity service configuration contains explicit options to require confirmed email and/or phone number.

It can be done the following way:

services
    .AddIdentity<User, Role>(options =>
    {
        options.SignIn.RequireConfirmedEmail = true;
        options.SignIn.RequireConfirmedPhoneNumber = true;
     });

The validation of the email is quite straight forward as the UserManager contains explicit token generator and its validator:

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

The generated token can be validated the following way:

var result = await _userManager.ConfirmEmailAsync(user, code);

The above line will switch the user.EmailConfirmed flag to true if the token is valid.

Now the problem is that I don't see a similar method to generate a phone validation token and its equivalent method to validate it (which in turn should switch the user.PhoneNumberConfirmed flag to true if successful).

User manager contains however few methods to do a user phone change:

_userManager.GenerateChangePhoneNumberTokenAsync();

and

_userManager.VerifyChangePhoneNumberTokenAsync();

But it seems these methods don't switch the user.PhoneNumberConfirmed flag.

Am I missing something? What would be the correct way to confirm the user phone number (in other words to set user.PhoneNumberConfirmed to true) ?

1 Answers
Related