aboutyou / dart_packages

Dart and Flutter plugins maintained and used by @ABOUTYOU
222 stars 153 forks source link

Changed state and email fields to optional to match Apple's responses #432

Closed intonarumori closed 3 months ago

intonarumori commented 3 months ago

In this PR we updated the model objects to match Apple's responses.

The Issue

We were getting errors with the library if we omitted the state parameter in our call to getIDCredential or we were hiding our email address in the Apple Sign-in dialog. The error was pretty obscure:

TypeError: Instance of '_TypeError': type '_TypeError' is not a subtype of type 'JSObject'

What was actually happening

The solution

Couple of questions remain

tp commented 3 months ago

@intonarumori Thanks for the thorough investigation.

Surely I was always testing with a state parameter, so it might be that the types here are wrong.

I will verify this locally and if it fixes the state-less and/or "second login" flow as you describe, will prepare a release ASAP.

tp commented 3 months ago

Should we do the same for name.firstName and name.lastName?

I think that is already working fine because the whole name object is optional, and thus won't error when this is omitted.

tp commented 3 months ago

Just tested this on web without any requested scopes (no name or mail), and without passing a nonce or state either.

Before (on master) it failed, and with this fix it worked fine.

So thanks a ton @intonarumori!

tp commented 3 months ago

Should we improve the code in the catch block here so if parsing errors in the future arise we get more informative error messages and can fix them quicker?

Yes, that would be a great follow-up. The code should not assume that it's only that specific error type. Will have to check whether an is check would work on there, and if it doesn't match forward the "raw" error.