自定义电子邮件确认令牌 [英] Custom email confirmation token

查看:664
本文介绍了自定义电子邮件确认令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用用户管理标识2.0框架。结果
不幸的是,我的用例的帐号激活/重置密码不能使用直接链接,这样用户就不得不从他的电子邮件拷贝code,并将其粘贴到网站做了。

I'm using the Identity 2.0 framework for user management.
Unfortunately, in my use case an account activation/password reset cannot be done using a direct link, so the user would have to copy the code from his e-mail and paste it into the website.

这是由的UserManager 的默认生成的code GenerateEmailConfirmationTokenAsync 的方法是很长,它跨越3行文字。
我试图重写此方法,生成一个较短的code这是更加人性化。这不起作用,因为 ConfirmEmailAsync 方法总是返回无效令牌(此方法不叫 GenerateEmailConfirmationTokenAsync 方法的话)。

The code that is generated by the UserManager's default GenerateEmailConfirmationTokenAsync method is very long, it spans about 3 lines of text. I tried to override this method, generating a shorter code that is more user friendly. This doesn't work, as the ConfirmEmailAsync method always returns "invalid token" (this method doesn't call the GenerateEmailConfirmationTokenAsync method at all).

我不知道确认code是如何存储和I preFER使用Identity框架的默认存储机制,而不是手动将其存储在数据库中。

I do not know how the confirmation code is stored and I prefer to use the default storage mechanism of the Identity Framework instead of storing it manually in the database.

由于身份2.0框架是闭源的,我不知道如何着手。是否有可能生成自定义(短)确认codeS,我应该除了我已经做了覆盖哪些方法?

As the Identity 2.0 framework is closed source, I am not sure how to proceed. Is it possible to generate custom (shorter) confirmation codes and what methods should I override in addition to what I already did?

推荐答案

ASP.NET身份使用 UserTokenProvider 的UserManager 来生成和验证令牌。基本上,它要求:

ASP.NET Identity uses the UserTokenProvider of the UserManager to generate and validate the token. Basically it calls:

this.UserTokenProvider.GenerateAsync("Confirmation", this, tUser);

要生成令牌以及

this.UserTokenProvider.ValidateAsync("Confirmation", token, this, tUser);

要验证它。

所以,你可以实现自己的 IUserTokenProvider< TUSER,TKEY的> 或延长一个默认并设置为 UserManager.UserTokenProvider

So you can implement your own IUserTokenProvider<TUser, TKey> or extend the the default one and set that as UserManager.UserTokenProvider.

这篇关于自定义电子邮件确认令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆