Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identity Email Confirmation fails when token generated in a different assembly #22081

Closed
dotcom9 opened this issue May 21, 2020 · 6 comments
Closed
Labels
area-identity Includes: Identity and providers Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.

Comments

@dotcom9
Copy link

dotcom9 commented May 21, 2020

Describe the bug

An ASPNET Identity email confirmation token generated in a different assembly fails when used in the UserManager.ConfirmEmailAsync method.

To Reproduce

  1. Clone https://github.com/dotcom9/email-confirmation-token-bug
  2. Open in Visual Studio
  3. Run EF migrations
  4. Register a user
  5. Copy the UserId field value for the new user and paste in the _userId literal at the top of Mvc.HomeController
  6. Run the Mvc and Api projects
  7. Click on "Get token from Api" button
  8. Observe error "invalid token"
  9. Click on "Get token locally" button
  10. In database, observe user account has been confirmed

Further technical details

  • ASP.NET Core version: 3.1

  • Include the output of dotnet --info
    dotnetinfo.txt

  • The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version
    vs-info.txt

@javiercn javiercn added the area-identity Includes: Identity and providers label May 21, 2020
@blowdart
Copy link
Contributor

@HaoK do email tokens get wrapped up in data protection somehow?

@HaoK
Copy link
Member

HaoK commented May 21, 2020

Yeah by default they use dataprotection

@blowdart
Copy link
Contributor

@dotcom9 What's happening here is data protection, we take tokens and encrypt and sign them. However your applications are configured to share the keys used for this, so one app can't decrypt tokens encrypted with the other.

There are a couple of things to do, first configure the apps to share a keyring, and second set the apps to have the same application identifier.

How you share depends on your configuration, if, for example, both the api and web site are on the same machine you can use the file system. If they're in azure you can use blob storage. You can see the configuration options in the docs, these are the Persist* functions. Note that when you configure shared locations you also need to consider how the keys are protected in storage, these are the Protect* functions.

Once you have the keys shared you also need to configure the application name otherwise application isolation is going to kick in

@blowdart blowdart added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label May 21, 2020
@dotcom9
Copy link
Author

dotcom9 commented May 22, 2020

This is great information, and with it I have solved my problem. Many thanks. I was unaware of Identity's dependency on DataProtection, though of course it makes sense. I couldn't find an obvious reference to it in the Identity documentation. Did I miss something, or is it an omission? I would have thought my use case was a common one.

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels May 22, 2020
@blowdart
Copy link
Contributor

To be honest your use case isn't that common. I don't think I've actually seen it before, hence there being no documentation. Usually identity is self contained within the app, so it the use of data protection is handled automatically :)

I'm going to go ahead and close this now, because your problem is solved, but it you encounter more problems please feel free to reopen.

@dotcom9
Copy link
Author

dotcom9 commented May 22, 2020

Ok, thanks for the help.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-identity Includes: Identity and providers Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update.
Projects
None yet
Development

No branches or pull requests

4 participants