xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 505 forks source link

[Bug] Xamarin.Essentials WebAuthenticator on iOS cannot complete the registration #1680

Open Grzesik opened 3 years ago

Grzesik commented 3 years ago

Description

When I try to login on my iPhone (13.4) with the Webautenticator (not the native AppleSignInAuthenticator) I get the dialog to login, but after a click on login, I get an error “Registration not completed”. On the Azure, the service seems to work OK. Google works fine. The AppleSignInAuthenticator works fine. My app is based on the sample in in the Xamarin.Essentials samples. I tried to test the behavior of the WebAuthenticator when the iOS version is less than 13. My phone has the version 13.4.

The Log from the Azure App Service: Application:2021-02-07 22:31:09.555 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request starting HTTP/1.1 GET https://shoporderapi.azurewebsites.net/api/mobileauthshop/Apple - - Application:2021-02-07 22:31:10.041 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint 'ShopOrderWeb.Controllers.MobileAuthShopController.Get (ShopOrderWeb)' Application:2021-02-07 22:31:10.144 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Route matched with {action = "Get", controller = "MobileAuthShop"}. Executing controller action with signature System.Threading.Tasks.Task Get(System.String) on controller ShopOrderWeb.Controllers.MobileAuthShopController (ShopOrderWeb). Application:2021-02-07 22:31:10.182 +00:00 [Information] AspNet.Security.OAuth.Apple.AppleAuthenticationHandler: Apple was not authenticated. Failure message: Not authenticated Application:2021-02-07 22:31:10.194 +00:00 [Information] AspNet.Security.OAuth.Apple.AppleAuthenticationHandler: AuthenticationScheme: Apple was challenged. Application:2021-02-07 22:31:10.202 +00:00 [Information] Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker: Executed action ShopOrderWeb.Controllers.MobileAuthShopController.Get (ShopOrderWeb) in 49.5103ms Application:2021-02-07 22:31:10.203 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executed endpoint 'ShopOrderWeb.Controllers.MobileAuthShopController.Get (ShopOrderWeb)' Application:2021-02-07 22:31:10.262 +00:00 [Information] Microsoft.AspNetCore.Hosting.Diagnostics: Request finished HTTP/1.1 GET https://shoporderapi.azurewebsites.net/api/mobileauthshop/Apple - - - 302 - - 706.4353ms

Expected Behavior

The WebAuthenticator can login on iPhone and delivers the accesstoken

Actual Behavior

The call to the

r = await WebAuthenticator.AuthenticateAsync(authUrl, callbackUrl);

shows the login dialog, but ends with the message “Registration not completed" and I get an exception in the app a the end.

Basic Information

Grzesik commented 3 years ago

Hi, I solved the problem. The configuration for oAuth2 for Apple is more complicated as described here:

https://docs.microsoft.com/en-us/xamarin/ios/platform/ios13/sign-in

It works only for iOS >= 13 . For iOS < 13 and for other platforms, which use iOS oAuth2, it is necessary to configure more in iOS Certificates.

  1. Create an identifier for your app explicit
  2. Create a Key for the app and download the certificate for Azure
  3. Create a new ServiceId -> the id is your clientId in Azure Here Domain is like the url in azure XXXXXXXX.azurewebsites.net The redirect url is: https:// XXXXXXXX.azurewebsites.net/signin-apple

The API must work in Azure, because Apple doesn’t accept the localhost for test.

You can read more about the configuration here:

https://medium.com/@sirajul.anik/sign-in-with-apple-verify-mobile-app-payload-under-5-minutes-for-backend-developers-d69c2217ddec

It works well in iOS. In my UWP and Android App I get the token, but the email and the name is empty. I coudn’t find any option to get it. Without the email it is useless to use the iOS oAuth2 in other systems, apart from iOS. If you find a possibility to get the email on Android or UWP, let me know.