How do you use Auth0 from Xamarin.Forms? Actually seems to be insanely easy.

Here's what I have from an Android implementation. (To use in Forms, you have to do the whole DependencyService thing from Phoneword. So this will be your Android implementation of some interface that defines GetToken.)

public async Task<string> GetToken()
    var auth0 = new Auth0Client(
        "",     // domain
        "whateverYourClientIdIs");        // clientId

    // 'this' could be a Context object (Android) or UIViewController, UIView, UIBarButtonItem (iOS)
    var user = await auth0.LoginAsync(Forms.Context);    
    // `Forms.Context` is the secret sauce ^^^^ for `Context` in Android

    return user.IdToken;

See this question at StackOverflow for a little more -- there's a spot in "Connections - Social" in your Auth0 dashboard that has something that's similar to the picture at SO that I'll include below:

Picking Permissions

Click on the picture for a bigger version. I want to use Gmail, so I'm setting it up just like it looks there.

Easy enough. Now I'm just worried what happens when you get your 7001st client. And embarrassed that I'm doing OAuth through a provider, but man, that was easy.

Labels: , , ,