gpt4 book ai didi

Azure 应用服务轻松身份验证

转载 作者:行者123 更新时间:2023-12-03 03:03:51 25 4
gpt4 key购买 nike

我有一个 Azure 移动后端,设置了用于 facebook 和 google 身份验证的简单例份验证,并且它按预期工作。

每次用户登录任何受支持的提供商时,我希望能够验证它是否是新用户(电子邮件不在数据库中),而无需从客户端进行额外的调用。这可能吗?

最佳答案

Every time a user signs in with any of the supported providers, I want to be able to verify if it's a new user or not (e-mail not in database), without make an additional call from client. Is this possible?

据我所知,我们无法直接验证是否是新用户。

无论您使用服务器流还是客户端流,easy auth 都只会返回访问 token 供客户端访问移动后端资源,不会检查用户是新用户还是老用户。

如果你想实现这个需求,你需要自己编写逻辑。

用户登录成功后即可编写代码。

例如,Facebook 登录。

如果您已成功登录,您可以调用 GetAppServiceIdentityAsync 扩展方法来获取登录凭据,其中包括向 Facebook Graph API 发出请求所需的访问 token 。

// Get the credentials for the logged-in user.
var credentials =
await this.User
.GetAppServiceIdentityAsync<FacebookCredentials>(this.Request);

if (credentials.Provider == "Facebook")
{
// Create a query string with the Facebook access token.
var fbRequestUrl = "https://graph.facebook.com/me/feed?access_token="
+ credentials.AccessToken;

// Create an HttpClient request.
var client = new System.Net.Http.HttpClient();

// Request the current user info from Facebook.
var resp = await client.GetAsync(fbRequestUrl);
resp.EnsureSuccessStatusCode();

// Do something here with the Facebook user information.
var fbInfo = await resp.Content.ReadAsStringAsync();
}

然后就可以根据用户信息查询数据库了。

更多关于服务器端如何获取用户信息,可以引用How to: Retrieve authenticated user information .

关于Azure 应用服务轻松身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46312517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com