Cross platform plugin for doing Google Authentication for Xamarin iOS and Android apps
The short answer is that Google has updated its security restrictions for OAuth flow. They are not going to allow native web-views to initiate OAuth flows, but rather are encouraging people to use the OS browsers to do so.
Here are the basic steps that you need to follow to add Google Authentication into your Xamarin forms application
-
Setup your Application on the Google developer's console to use OAuth2. Guide here. Make sure you select the Web Application option.
-
Download this repository and copy over the GoogleAuth, Plugin.GoogleAuth, Plugin.GoogleAuth.Android and Plugin.GoogleAuth.iOS folders into your application and add them into your solution in VS or Xamarin Studio.
-
Add references to the Plugin.GoogleAuth and Plugin.GoogleAuth.Abstractions projects into your PCL project.
-
Add references to the Plugin.GoogleAuth.Android and Plugin.GoogleAuth.Abstractions projects into your Android project.
-
Add references to the Plugin.GoogleAuth.iOS and Plugin.GoogleAuth.Abstractions projects into your Android project.
-
Inside your platform specific projects initialize the Google Authentication service as shown below.
IGoogleAuthenticationService _service; _service = CrossGoogleAuth.Current; Dictionary<string, object> googleSignInConfig = new Dictionary<string, object> { {"clientId", "<client-id>"}, {"context", this} // Android only }; _service.Init(googleSignInConfig);
-
For further usage details, check out the GoogleAuthSample project in this repository.
- Convert this into a NuGet package !