Essentials: [Bug] AppleSignInAuthenticator doesn't return name

Created on 26 May 2020  Â·  25Comments  Â·  Source: xamarin/Essentials

Description

AppleSignInAuthenticator doesn't return name even when it is returned from Apple services.

When debugging through source code the issue seems to be in this code:
appleAccount.Properties.Add("name", NSPersonNameComponentsFormatter.GetLocalizedString(creds.FullName, NSPersonNameComponentsFormatterStyle.Default, NSPersonNameComponentsFormatterOptions.Phonetic));
Even when cred.FullName value is populated, NSPersonNameComponentsFormatter.GetLocalizedString converts it to null.

Note: creds.FullName populated only once, when user first allows app to be used with Apple Id.

Steps to Reproduce

  1. Use following call from iOS app registered with Apple Sign In on iOS 13
    r = await AppleSignInAuthenticator.AuthenticateAsync(new AppleSignInAuthenticator.Options() { IncludeFullNameScope = true });
  2. Retrieve value from r.Properties["name"]

Expected Behavior

The value should be populated with user's name.

Actual Behavior

The value is null

Basic Information

  • Version with issue: 1.5.3.2
  • Last known good version: None
  • IDE: Visual Studio
  • Platform Target Frameworks:

    • iOS:

  • Nuget Packages:
  • Affected Devices: iOS devices

Screenshots


Non visual

Reproduction Link

bug

Most helpful comment

Hi all, I just pushed the PR build to the preview feed. Let me know if this now works.

Version: 1.6.0-pr.1534.1
Feed: https://aka.ms/xamarin-essentials-ci/index.json

All 25 comments

I'm not getting any result from IncludeEmailScope either.

I'm not getting any result from IncludeEmailScope either.

I think I got email, but please note that it works only on first call, when app is not yet registered and user is prompted to share email. Subsequent calls don't return email, but it's not fault of AppleSignInAuthenticator component, but Apple Services.

I have the same problem, I can receive the email the first time but the name is empty.

Email is included in the id_token claims. However, I have the same issue with name which is empty despite the fact that I passed options :

oauthResult = await AppleSignInAuthenticator.AuthenticateAsync(
                    new AppleSignInAuthenticator.Options()
                    {
                        IncludeEmailScope = true,
                        IncludeFullNameScope = true,
                    });

I have almost same issue BUT ONLY in release (TestFlight and Production) version... In Debug (on Windows Hot Restart) everything works fine...

Under my deep investigation, the problem don't happens when I use fingerprint authentication... Just using Face authentication...

Any news about that issue?

Under my deep investigation, the problem don't happens when I use fingerprint authentication... Just using Face authentication...

Any news about that issue?

In my case the problem was with fingerprint authentication

I made +3~4 Apple SignIn integrations at last 45 days and I know why this happens now...

On iOS 13+ The JwtToken is created locally... When the user "tap" on SignIn with Apple for the first time, a popup shows requesting the Name (or Full Name) of user (by default, the field starts with user's AppleId Full Name) and select e-mail options (important thing, a option to omit the e-mail has present, the app need to take care about this too)... So... When user confirm your "new" account data, a JwtToken with full data are created...

So, on the next times, JUST AppleUserId and e-mail (case user was select an "use e-mail" option on the first time) are used to compose the JwtToken on Fingerprint or FaceId...

We are nothing to do....

So, on the next times, JUST AppleUserId and e-mail (case user was select an "use e-mail" option on the first time) are used to compose the JwtToken on Fingerprint or FaceId...

We are nothing to do....

This bug is not about "next times". This is about first call, name is missing on first call. When I debugged through source code it was returned from iOS API but then in Xamarin code it disappears due to conversion to .NET string

This may or may not help people. I didn't know this existed in Xamarin Essentials, and followed the sample at https://github.com/Redth/Xamarin.AppleSignIn.Sample when implementing Apple sign in on my app. The code for Xamarin Essentials seems to be where a lot of the code here came from as well. I also noticed that 'Full Name' was blank using the sample, even with the original requests. But I also saw that GivenName and FamilyName in the credentials were populated as needed, so I just added two properties to the AppleAccount class in the sample, and I was able to use those with no problems!

My guess is that this could be fixed by adding those two fields in this file:

https://github.com/xamarin/Essentials/blob/f6dd837841b57fff7cee1a7fb8e6512fa5158108/Xamarin.Essentials/WebAuthenticator/AppleSignInAuthenticator.ios.cs

        appleAccount.Properties.Add("given_name", creds.GivenName);
        appleAccount.Properties.Add("family_name", creds.FamilyName);

Any updates? My submission to Apple store is stuck because they now require Apple Sign In support, and the workflow requires getting the name of the user. And since Apple doesn't have any API to get the name, there is no workaround.

Has anything changed? I am in this same situation. I authenticate with firebase using the Token id. But the app I'm developing is sales, so the name and email is essential. I am thinking of requesting login with the Apple account and then immediately request name and email. Will Apple accept it that way? So I link the email to idToken in the backend. I thought about it because of the delivery time of the app.

Has anything changed? I am in this same situation. I authenticate with firebase using the Token id. But the app I'm developing is sales, so the name and email is essential. I am thinking of requesting login with the Apple account and then immediately request name and email. Will Apple accept it that way? So I link the email to idToken in the backend. I thought about it because of the delivery time of the app.

I ended up copying source code from AppleSignInAuthenticator to my application and making suggested change using GivenName and FamilyName, seems to be working, testing it now. Will go back to Xamarin.Essentials when they fix it

Algo mudou? Eu estou na mesma situação. Eu me autentico com o firebase usando o código do token. Mas o aplicativo que estou desenvolvendo é o de vendas, então o nome e o e-mail são essenciais. Estou pensando em solicitar login com a conta da Apple e imediatamente solicitar nome e e-mail. A Apple aceitará dessa forma? Então, vinculo o e-mail a idToken no backend. Pensei nisso por causa do prazo de entrega do app.

Acabei copiando o código-fonte do AppleSignInAuthenticator para o meu aplicativo e fazendo a alteração sugerida usando GivenName e FamilyName, parece estar funcionando, testando agora. Voltará para Xamarin.Essentials quando eles consertarem

thanks!

Hi, I'm following this example:
https://github.com/f-miyu/Plugin.FirebaseAuth/blob/master/Plugin.FirebaseAuth.Sample/Plugin.FirebaseAuth.Sample.iOS/Services/AppleService.cs

      `var provider = new ASAuthorizationAppleIdProvider();

        var nonce = GenerateNonce(32);

        var request = provider.CreateRequest();

        request.RequestedScopes = new[] { ASAuthorizationScope.FullName, ASAuthorizationScope.Email };
        request.Nonce = GetHashedNonce(nonce);

        var controller = new ASAuthorizationController(new[] { request });

        var authorizationControllerDelegate = new AuthorizationControllerDelegate(UIApplication.SharedApplication.KeyWindow);

        controller.Delegate = authorizationControllerDelegate;
        controller.PresentationContextProvider = authorizationControllerDelegate;

        controller.PerformRequests();

        var credential = await authorizationControllerDelegate.GetCredentialAsync().ConfigureAwait(false);

        var idToken = new NSString(credential.IdentityToken, NSStringEncoding.UTF8).ToString();`

GivenName and FamilyName is not returning. It just returns credential.IdentityToken and user code. It also does not return mail and name.

It's important that these values are returned only first time, when user allows access to the app, they are not returned on subsequent runs.

I think the issue is in line 51

NSPersonNameComponentsFormatter.GetLocalizedString(creds.FullName, NSPersonNameComponentsFormatterStyle.Default, NSPersonNameComponentsFormatterOptions.Phonetic);

In my case it always returns "" - no matter how much I try to tweak the options.

I fixed it temporarily by just fetching the full name like this :

creds.FullName.GivenName + " " + creds.FullName.FamilyName

I know its a quick and dirty hack, but I wonder if there is something wrong with NSPersonNameComponentsFormatter and that might be where the real issue is ?

É importante que esses valores sejam retornados apenas na primeira vez; quando o usuário permite o acesso ao aplicativo, eles não são retornados nas execuções subsequentes.

Hi, allow me a question about this please. In debug mode does the same thing happen, only the first time? Is there a way around this in debug mode?

@Junior-OliveiraDeveloper

É importante que esses valores sejam retornados apenas na primeira vez; quando o usuário permite o acesso ao aplicativo, eles não são retornados nas execuções subsequentes.

Hi, allow me a question about this please. In debug mode does the same thing happen, only the first time? Is there a way around this in debug mode?

It's how Apple API works, it's not related to Xamarin or this library. The name and emails are returned only when app is authorized first time. You are expected to get these values at these point and save somewhere.

BTW, question to you. @Junior-OliveiraDeveloper , you mentioned above that your workaround was to make separate call to get user's name. I couldn't find such option. Was it hypothetical, or you can point me to the information how to do this?

@maxal1917

Hello, I actually check if the email or password is missing. If so, I make a pop-up request: It is important for this application to know your name and email address to complete your purchase. Please enter your name and email in the field below. I'm going to send it to Apple this week, but I don't know if they'll accept it that way.

I know it's not ideal. If anyone has an elegant solution please let me know.

Hello, forget what I said. They responded, and rightly thought it was wrong.

Apple's response:
Sign in with Apple is designed to be a self-contained, all-in-one login system. With security features like built-in two-factor authentication, you can remove additional sign-up steps so users can focus on your app's content and features.

I can't solve this. :(

any news?

I am having a look right now and hope to get a fix out ASAP.

I am trying to figure out how to reset the state so I can get the email and name again. Is there a way to tell Apple that we are a new app and user?

I have fixed the bug, working on a PR. Thanks for all the info and patience. I will try and get a preview out ASAP so you can try it out.

Hi all, I just pushed the PR build to the preview feed. Let me know if this now works.

Version: 1.6.0-pr.1534.1
Feed: https://aka.ms/xamarin-essentials-ci/index.json

Was this page helpful?
0 / 5 - 0 ratings