It's was a litte pain in the ass because one project must have two oAUth clients, one per each platform (Android/ iOS) because it's the way that Google works. All the oAuth providers works in the same way?
Xamarin Auth is a nuget package to work with oAuth in Xamarin and it does the hard work with the oAuth flow. This libray includes the OAuthLoginPresenter that works in both platforms (it's not required to add custom UI in each platform) and the OAuth2Authenticator that allows us to handle the proccess with the events Completed and Error.
We have to manage the returnUrl of our OAuth2Authenticator in each platform, so in Android platform we have to use an activity interceptor that it's the place to setup the DataSchemes and DataPaths.
[IntentFilter(
actions: new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[]
{
"com.mookiefumi.blacksabbath",
"com.googleusercontent.apps.[YOUR_CLIENT_ID]",
"urn:ietf:wg:oauth:2.0:oob"
},
DataPaths = new[] { "/oauth2redirect" },
AutoVerify = true
)]
In iOS platform we have to add two Url Types in our Info.plist file (Advanced tab).
In Android platform the OAuthLoginPresenter uses CustomTabs. It doesn't work well so we have to call StartActicity int our CustomUrlSchemeInterceptorActivity because the browser is not closing automatically.
new Task(() =>
{
var intent = new Intent(ApplicationContext, typeof(MainActivity));
intent.AddFlags(ActivityFlags.ClearTop);
intent.AddFlags(ActivityFlags.SingleTop);
StartActivity(intent);
}).Start();
In iOS platform works without any issues.
Why always the Android platform have so many hacks or issues?
Google OpenId discover document