15 ratings
  • 1
  • 2
  • 3
  • 4
  • 5
5 star 8
4 star 2
3 star 0
2 star 3
1 star 2
Compatible with
  • iOS
  • Android

Auth0 SDK 0.5.0

Auth0

Add authentication with different sources, either social like Google, Facebook, Twitter, or enterprise like WAAD, Google Apps, AD, ADFS or any SAML Provider.

Auth0 is a cloud service that works as a Single Sign On hub between your apps and authentication sources. By adding Auth0 to your Xamarin app you can:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, 37Signals, or enterprise identity systems like Windows Azure AD, Google Apps, AD, ADFS or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
  • Support for integrating with third party APIs (AWS, Windows Azure Mobile Services, Firebase, Salesforce, and more!).
  • Analytics of how, when and where users are logging in.
  • Pull data from other sources and add it to the user profile, through JavaScript rules.

The library is cross-platform, so once you learn it on iOS, you're all set on Android.

Authentication with Widget

using Auth0.SDK;

var auth0 = new Auth0Client(
    "{domain}",
    "{clientID}");

// 'this' could be a Context object (Android) or UIViewController, UIView, UIBarButtonItem (iOS)
var user = await auth0.LoginAsync(this);
/*
- get user email => user.Profile["email"].ToString()
- get facebook/google/twitter/etc access token => user.Profile["identities"][0]["access_token"]
- get Windows Azure AD groups => user.Profile["groups"]
- etc.
*/
  • In order to request a refresh token, use auth0.LoginAsync(this, withRefreshToken: true) (see details).
  • You can obtain the {domain} and {clientID} from your application's settings page on the Auth0 Dashboard. You need to subscribe to Auth0 to get these values. The sample will not work with invalid or missing parameters. You can get a free subscription for testing and evaluation.

Authentication with your own UI

var user = await auth0.LoginAsync(this, "google-oauth2"); // connection name here
  • connection names can be found on Auth0 dashboard. E.g.: facebook, linkedin, somegoogleapps.com, saml-protocol-connection, etc.

Authentication with specific user name and password

var user = await auth0.LoginAsync(
  "sql-azure-database", // connection name here
  "jdoe@foobar.com",    // user name
  "1234");              // password

Get more details on our Xamarin tutorial.

Delegation Token Request

You can obtain a delegation token specifying the ID of the target client (targetClientId) and, optionally, an IDictionary<string, string> object (options) in order to include custom parameters like scope or id_token:

var options = new Dictionary<string, string>
{
    { "scope", "openid profile" },      // default: openid
};

var result = await auth0.GetDelegationToken(
  targetClientId: "{TARGET_CLIENT_ID}", // defaults to: ""
  idToken: "{USER_ID_TOKEN}", // defaults to: id_token of the authenticated user (auth0 CurrentUser.IdToken)
  options: options);

// id_token available throug result["id_token"]

Renew id_token if not expired

If the id_token of the logged in user has not expired ("exp" claim) you can renew it by calling:

var options = new Dictionary<string, string>
{
    { "scope", "openid profile" }, // default: passthrough i.e. same as previous time token was asked for
};

auth0.RenewIdToken(options: options);

Checking if the id_token has expired

You can check if the id_token for the current user has expired using the following code:

bool expired = auth0.HasTokenExpired();

If you want to check if a different id_token has expired you can use this snippet:

string idToken = // get if from somewhere...
bool expired = TokenValidator.HasTokenExpired(idToken);

Refresh id_token using refresh_token

You can obtain a refresh_token which never expires (unless explicitly revoked) and use it to renew the id_token.

To do that you need to first explicitly request it when logging in:

var user = await auth0.LoginAsync(this, withRefreshToken: true);
var refreshToken = user.RefreshToken;

You should store that token in a safe place. The next time, instead of asking the user to log in you will be able to use the following code to get the id_token:

var refreshToken = // retrieve from safe place
var result = await auth0.RefreshToken(refreshToken);
// access to result["id_token"];

Release Notes

  • Allow to customise WebRedirectAuthenticator screen title.
Write a Review

8 reviews

Homero Lara rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Since Google's latest changes on using webviews for oauth, this sdk is not worth using.

Posted on: May 24 / Version: 0.5.0
ASHISH RANJAN

The component is not getting install in visual studio.When i try to add it ,it is not showing the page to add it in App.Automatically component closed after tapping on it.

Posted on: May 12 / Version: 0.5.0
Alexandra Valkova

The component was cool, until Google stopped supporting webviews for authentication https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html Now I get a "disallowed_useragent" error page when I try to login on iOS :/

Posted on: May 5 / Version: 0.5.0
Jeff Weinstein rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Would love to see this actually maintained: It hasn't been updated since July 25, 2015!!

Posted on: February 20 / Version: 0.5.0
Technificent Consulting rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

It would be great if there was an example, preferably IOS, that shows how to make a request to Twitter and obtain a list of the user's friends. Other than that the basic login sample is simplistic and works well.

Posted on: February 2 / Version: 0.5.0
Brent Anderson rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

this thread shows an xplat approach for using this component under Xamarin Forms.

if you're interested in TouchId as well as the socials provided by this library, see this

Posted on: October 26, 2016 / Version: 0.5.0
Rick Graner rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Would love to see a "Xamarin Forms" specific version or steps to implement Forms with what you have here. I found a few articles online but they are not the best tech writers but I'm currently working through it so for ppl coming after me, it'll save them a ton of time.

HELL YES I love this company ... it's such a blessing to have smarter ppl them myself handle the SUCK/YAK of authentication/authorization for my sites/apps. Security is everyone's problem so let put more brains around it and have solid tools for us to use as a community.

Posted on: March 28, 2016 / Version: 0.5.0
Steve Finn rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Used Auth0 to provide authentication to an Android App and an Angular web site. Very easy to implement and the support provided by the Auth0 guys has been superb. Highly recommended.

Posted on: February 5, 2014 / Version: 0.1