
We always encounter the need for authentication in most of our applications. It's a struggling process to authenticate the user by interacting with services like Twitter, Facebook and so on.
Figure 1: Login
Here I'm creating a simple method of authentication using Xamarin.Auth.
The Xamarin.Auth component is a great time saver for authentication.
The authentication cardinals are given for authentication. Authenticators are responsible for managing the user interface and communicating with authentication services. Authenticators take a variety of parameters, like the Client ID, its authorization scope, the authorization URL, redirect URL and so on, since it varies depending on the authenticators.
- var auth = new OAuth2Authenticator
- (
- clientId: "", // your OAuth2 client id
- scope: "", // the scopes for the particular API you're accessing, delimited by "+" symbols
- authorizeUrl: new Uri(""), // the auth URL for the service
- edirectUrl: new Uri("")
- );
- auth.Completed += (sender, args) =>
- {
- if(args.IsAuthenticated)
- {
- var account =args.Account;
- // Do success work
- }
- else
- {
- // The user cancelled
- {
- };
All the info about the successful authentication will be in args.Account.
The GetUI() method returns the corresponding UINavigationController in iOS and corresponding Intent in Android.
- //iOS
- PresentViewController (auth.GetUI (), true, null);
- //Android
- activity.StartActivity(auth.GetUI(activity));
- // On iOS:
- AccountStore.Create ().Save (args.Account, "Facebook");
- // On Android:
- AccountStore.Create (this).Save (args.Account, "Facebook");
Xamarin.Auth provides all the popular services for authentication. We can also create our own authenticator by Username and Password using FormAuthenticator.SignInAsync().
A small sample of Authentication sample is added with this article as a reference.

qaz wsxPosted Jun 8, 2018, 6:54 AM
Getting disallowed_useragent error for google, please help
Massimo De VitisPosted Apr 5, 2017, 2:07 PM
Hi, it's possible to have a list of users facebook?
Massimo De VitisPosted Apr 5, 2017, 2:06 PM
Hi, how it's possible to have the list of users ?
Veswanth RajuPosted Jan 11, 2017, 5:27 AM
Can you please tell me how to use FormAuthenticator.SignInAsync(); for my own authentication.
Vikas AgarwalPosted Aug 30, 2016, 8:48 AM
I download this example and run it, but can't able to load login page. I have created xamarin pcl and want to click on fb icon for fb authentication it is possible with pcl in xamarin?
Akash KumarPosted Mar 18, 2016, 12:53 AM
Can you send the steps to write the code for Facebook authentication?
Sudha SPosted Jan 5, 2016, 5:55 AM
Not able to see the login page, all can see is blank page
Vaikesh K PPosted Aug 17, 2015, 12:45 AM
Thanks Pankaj Kumar Choudhary :)
Vaikesh K PPosted Aug 17, 2015, 12:44 AM
Thanks Santhakumar Munuswamy sir :)
Vaikesh K PPosted Aug 17, 2015, 12:44 AM
Thanks Nilesh Jadav :)
Vaikesh K PPosted Aug 17, 2015, 12:44 AM
Thanks Sibeesh Venu :)
Vaikesh K PPosted Aug 17, 2015, 12:43 AM
ThanksRajeesh Menoth
Vaikesh K PPosted Aug 17, 2015, 12:43 AM
Thanks Rakesh Chavda Sir :)
Vaikesh K PPosted Aug 17, 2015, 12:43 AM
Thanks Karthikeyan K :)
Pankaj Kumar ChoudharyPosted Aug 16, 2015, 5:17 AM
Nice article sir...
Santhakumar MunuswamyPosted Aug 16, 2015, 2:17 AM
Nice Article. Thanks for sharing
Nilesh JadavPosted Aug 15, 2015, 5:13 AM
Nice one Vaikesh K P
Sibeesh VenuPosted Aug 15, 2015, 4:38 AM
Nice Share :)
Rajeesh MenothPosted Aug 15, 2015, 3:32 AM
Nice Share
RakeshPosted Aug 15, 2015, 3:31 AM
nice one
Karthikeyan KPosted Aug 15, 2015, 2:16 AM
Thanks for sharing