Skip to content

Expose UserManager<T>.GetChangeEmailTokenPurpose() #12609

Description

@lonix1

UserManager In 2.1 exposed the "purpose" constants, eg. ConfirmEmailTokenPurpose.

We relied on this in order to use userManager.VerifyUserTokenAsync().

Now those constants are gone, and there is a GetChangeEmailTokenPurpose() method in its place, which is protected.

Please make it public, otherwise the verify function is unusable.

(Subclassing just adds an unnecessary mess as this class already conceals a lot of complexity and should be usable as is.)

Activity

  1. blowdart commented on Jul 26, 2019

    @blowdart
    Contributor

    @HaoK another breaking change?

  2. added
    area-identity
    on Jul 26, 2019
  3. lonix1 commented on Jul 26, 2019

    @lonix1
    ContributorAuthor

    To be consistent, consider:

    Changing GetChangeEmailTokenPurpose() (and related) to public.

    OR, changing VerifyUserTokenAsync() to protected, because it becomes useless anyways.

  4. HaoK commented on Jul 26, 2019

    @HaoK
    Member
  5. lonix1 commented on Jul 26, 2019

    @lonix1
    ContributorAuthor

    It doesn't work when trying to change email, because now it uses GetChangeEmailTokenPurpose, which is protected. (Could be other uses cases too, haven't checked.)

    And as you can see, it was changed to "ChangeEmail:" + newEmail, so the constant you linked is dead code.

    It is used here and here.

  6. HaoK commented on Jul 26, 2019

    @HaoK
    Member

    Ok, that seems safe enough to expose in the future.

    So you can just call VerifyUserTokenAsync with "ChangeEmail:" + newEmail as the purpose in the short term.

    But there's no breaking change here

  7. reopened this on Jul 26, 2019
  8. HaoK commented on Jul 26, 2019

    @HaoK
    Member

    Something for the backlog / future @blowdart

  9. added this to the Backlog milestone on Jul 26, 2019
  10. lonix1 commented on Jul 26, 2019

    @lonix1
    ContributorAuthor

    Thanks for looking into this.

    I've opted to subclass instead, to avoid magic strings (as shown by this issue, it's a bad idea to rely on magic strings 😄).

    For anyone else migrating code to 2.2, note that if you subclass, it's important not to register the subclass with the container, but to replace the default during init:

    services
    .AddIdentityCore<User>()
    .AddUserManager<MyUserManager<User>>()    // <--- the magic

    And then it's as easy as this:

    public async Task<bool> ValidateEmailChangeToken(TUser user, string newEmail, string token) {
      return await VerifyUserTokenAsync(
        user,
        Options.Tokens.ChangeEmailTokenProvider,
        GetChangeEmailTokenPurpose(newEmail),
        token
      );
    }
  11. added
    affected-very-few
    enhancement
    severity-nice-to-have
    on Oct 6, 2020
  12. added theissue type on May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewarea-identityenhancementseverity-nice-to-have

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions