简体   繁体   English

MobileServiceUser 返回错误的 UserId

[英]MobileServiceUser returns wrong UserId

I have an existing user in my Xamarin Forms app whose Details are as follows:我的 Xamarin Forms 应用程序中有一个现有用户,其详细信息如下:

First Name: Jim Last Name: Smith ProviderLoginId = jsmith@google.com OAuth Provider: Google When I first create this user, I use the following method to authenticate against google as follows:名字:Jim 姓氏:Smith ProviderLoginId = jsmith@google.com OAuth 提供商:Google 当我第一次创建这个用户时,我使用以下方法对 google 进行身份验证,如下所示:

result = await AuthenticationClient.AcquireTokenInteractive("https://***.onmicrosoft.com/profile.read/profile.read")
                                .ExecuteAsync();

            JObject objToken = new JObject();
            objToken.Add("access_token", result.IdToken);
            MobileServiceUser user = await App.syncMgr.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, objToken);

Now, I take the UserId property from the MobileServiceUser user variable and store it into my User Table as primary key.现在,我从 MobileServiceUser 用户变量中获取 UserId 属性并将其作为主键存储到我的用户表中。

Subsequently, I create another new user with the following details:随后,我使用以下详细信息创建另一个新用户:

First Name: Jim Last Name: Smith ProviderLoginId = jsmith@hotmail.com OAuthProvider: Microsoft名字:Jim 姓氏:Smith ProviderLoginId = jsmith@hotmail.com OAuthProvider:Microsoft

When I create the user using the same steps as above, I get the same UserId back from Azure. Obviously, I am not able to store it in my User table for the second user.当我使用与上述相同的步骤创建用户时,我从 Azure 得到相同的 UserId。显然,我无法将它存储在第二个用户的用户表中。 This only happens when the first name and the last name are the same regardless of which ProviderLoginId was used (whether it was Google OAuth or Microsoft OAuth).这只会在名字和姓氏相同时发生,无论使用哪个 ProviderLoginId(无论是 Google OAuth 还是 Microsoft OAuth)。

Should I not be getting a unique UserId in each case?我不应该在每种情况下都获得唯一的 UserId 吗? Since the bug surfaces only when the first and last names are same, I am assuming it is some sort of a bug.由于错误仅在名字和姓氏相同时才会出现,因此我假设这是某种错误。

Any and all help is appreciated.任何和所有的帮助表示赞赏。

You are using the older client, which is no longer supported.您使用的是不再受支持的旧版客户端。

You should be submitting the access token to the service, not the IdToken.您应该将访问令牌提交给服务,而不是 IdToken。 You haven't stated what the AuthenticationClient is, but hopefully it is ADAL (since the older service doesn't work with MSAL).您尚未说明 AuthenticationClient 是什么,但希望它是 ADAL(因为旧服务不适用于 MSAL)。

The newer client and service completely abstracts the authentication code, allowing you to use whatever authentication mechanism you like and just dealing with standard OAuth2/OIDC and bearer tokens (Authorization header) instead of the non-standard X-ZUMO-AUTH header that was used in the past.较新的客户端和服务完全抽象了身份验证代码,允许您使用您喜欢的任何身份验证机制,只需处理标准 OAuth2/OIDC 和不记名令牌(授权标头)而不是使用的非标准 X-ZUMO-AUTH header在过去。 My recommendation is to upgrade the client and server.我的建议是升级客户端和服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM