WebApi 2 从 Google 身份验证 OpenID -> oAuth2 更改 - 更改安全句柄
WebApi 2 Change from Google Authentication OpenID -> oAuth2 - Changes Security handle
当我开始我的项目时 Google 允许在不需要真正注册的情况下使用 OpenID..
现在已经消失了,我已经将项目移植到新的方法中……但是
问题是用户将获得新的安全令牌,因此将用户视为新用户。
你们有没有解决这个问题,这样我就不需要要求所有用户创建新帐户,然后让我 link 使用新帐户来使用旧帐户?
我决定 Google 电子邮件可以是我给现有用户的 link。
如果您在 ASP.NET/WEBAPI 中使用 Identity 的标准实现,则更改:AccountControler.cs - ExternalLoginCallback
这样做是在 Google 用户不存在时查找电子邮件并向现有用户添加登录名,如下所示:
// Sign in the user with this external login provider if the user already has a login
var user = await UserManager.FindAsync(loginInfo.Login);
插入:
//Google Migration. If not existing then check if the Google email exists and if it does the change the LoginProvider key and try to login again
if (user == null && loginInfo.Login.LoginProvider == "Google" && email != "")
{
xxxEntities db = new xxxEntities();
var existingUser = db.user_profiles.Where(e => e.eMail == (string)email).Where(p => p.created_from == "Google");
if (existingUser.Count() > 0)
{
var existingID = existingUser.Single().userFK;
var result = await UserManager.AddLoginAsync(existingID, loginInfo.Login);
if (result.Succeeded)
{
//Now retry the check if the user with this external login provider if the user already has a login
user = await UserManager.FindAsync(loginInfo.Login);
}
}
}
到这里:
//Now for the normal Check
if (user != null)
{
请注意查找是我拥有的一些内部对象,它可以通过向 UserManager 添加电子邮件查找在 OOTB 实现中完成,或者像我一样在您自己的用户管理对象中查找它
当我开始我的项目时 Google 允许在不需要真正注册的情况下使用 OpenID.. 现在已经消失了,我已经将项目移植到新的方法中……但是 问题是用户将获得新的安全令牌,因此将用户视为新用户。
你们有没有解决这个问题,这样我就不需要要求所有用户创建新帐户,然后让我 link 使用新帐户来使用旧帐户?
我决定 Google 电子邮件可以是我给现有用户的 link。 如果您在 ASP.NET/WEBAPI 中使用 Identity 的标准实现,则更改:AccountControler.cs - ExternalLoginCallback
这样做是在 Google 用户不存在时查找电子邮件并向现有用户添加登录名,如下所示:
// Sign in the user with this external login provider if the user already has a login
var user = await UserManager.FindAsync(loginInfo.Login);
插入:
//Google Migration. If not existing then check if the Google email exists and if it does the change the LoginProvider key and try to login again
if (user == null && loginInfo.Login.LoginProvider == "Google" && email != "")
{
xxxEntities db = new xxxEntities();
var existingUser = db.user_profiles.Where(e => e.eMail == (string)email).Where(p => p.created_from == "Google");
if (existingUser.Count() > 0)
{
var existingID = existingUser.Single().userFK;
var result = await UserManager.AddLoginAsync(existingID, loginInfo.Login);
if (result.Succeeded)
{
//Now retry the check if the user with this external login provider if the user already has a login
user = await UserManager.FindAsync(loginInfo.Login);
}
}
}
到这里:
//Now for the normal Check
if (user != null)
{
请注意查找是我拥有的一些内部对象,它可以通过向 UserManager 添加电子邮件查找在 OOTB 实现中完成,或者像我一样在您自己的用户管理对象中查找它