问题描述
我仅在我的 asp.net mvc 5 应用程序中启用了 Google 身份验证.我看到当我被重定向到 googles auth 屏幕时,我要求获得查看用户名和电子邮件地址的权限.然后我从 Google 返回,登录并命名我的新用户.
I have enabled Google Auth only within my asp.net mvc 5 app.I see that when I am redirected to googles auth screen I am asking for permission to view the users name and email address. I then return from Google, log in, and name my new user.
我显然已要求获得查看电子邮件地址的权限,但默认情况下不会存储该地址.我将如何将其存储在用户表中?
I have obviously asked for permission to view the email address, but by default this is not stored. How would I store this in the users table?
我已尝试编辑 startup.auth 中的选项,但没有任何与电子邮件相关的选项.通过 oAuth 执行此操作时,您需要手动请求它.我只是不知道我应该在哪里询问电子邮件地址...
I have tried editing the options in startup.auth, but there aren't any pertaining to the email. When doing this via oAuth you manually ask for it. I just don't know where exactly I should be asking for the email address...
另外,我将如何询问他们的谷歌帐户图片?
Also how would I go about asking for their google account picture?
推荐答案
您可以从 ClaimIdentity 作为电子邮件声明检索它
You can retrieve it from ClaimIdentity as an Email Claim
var email = externalIdentity.FindFirstValue(ClaimTypes.Email);
这篇关于在 mvc 5 中使用 google auth 时如何检索电子邮件地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!