Leigh Ciechanowski
Leigh Ciechanowski

Reputation: 1317

Auth0 and Xamarin How Do I Use Refresh Tokens

I'm using Auth0 from a Xamarin.iOS app. Currently, I'm authenticating users with this code:

var user = await auth0.LoginAsync(this, "facebook", true);

How do I use the refresh token that is returned in the future. At the moment I have to run this code everytime. I have looked through the documentation on Auth0 but I cannot find anything which shows how to use the refresh token.

The full code looks like this:

public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        LinkedInLoginButton.TouchUpInside += (sender, e) => {
            Login("linkedin", sender);
            };
        FacebookLoginButton.TouchUpInside += (sender, e) =>{
            Login("facebook", sender);
            };

    }

public async void Login(string provider, object sender)
    {
        var user = await auth0.LoginAsync(this, provider, true);
    }

Upvotes: 0

Views: 741

Answers (1)

Yuri S
Yuri S

Reputation: 5370

The method depends if token_id is expired or not. Checking if the id_token has expired

bool expired = auth0.HasTokenExpired();

Renew id_token if token of the logged in user has not expired

var renew = await auth0.RenewIdToken(optional options);

Refresh id_token using refresh_token received at login

var result = await auth0.RefreshToken(refreshToken);

Also here is the good sample: https://github.com/auth0/Xamarin.Auth0Client/blob/master/samples/Auth0Client.iOS.Sample/Auth0Client_iOS_SampleViewController.cs

Upvotes: 2

Related Questions