Hello Auth0 Support Team (and Community!)
I have implemented Auth0 Authentication for a Xamarin Forms App using the example provided here: (https://auth0.com/docs/quickstart/native/xamarin/01-login ).
Is there a refresh token example? And/Or, is there a suggested best-practice for Xamarin Forms app to utilize a refresh token when the access token expires OR, when the user closes/returns to the mobile app so that they do not need to login again?
Any help by anyone would be greatly appreciated.
Hey, did you try using “offline_access” scope in these two lines?
}, this);
SetContentView(Resource.Layout.Main);
FindViewById<Button>(Resource.Id.LoginButton).Click += LoginButtonOnClick;
FindViewById<Button>(Resource.Id.LogoutButton).Click += LogoutButtonOnClick;
FindViewById<Button>(Resource.Id.UserButton).Click += UserButtonOnClick;
_userDetailsTextView = FindViewById<TextView>(Resource.Id.UserDetailsTextView);
_userDetailsTextView.MovementMethod = new ScrollingMovementMethod();
writeLine = (s) => _userDetailsTextView.Text += s + "\n";
clearText = () => _userDetailsTextView.Text = "";
}
private async void LoginButtonOnClick(object sender, EventArgs eventArgs)
{
clearText();
writeLine("Starting login...");
var loginResult = await _auth0Client.LoginAsync();
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
private async void LoginButton_TouchUpInside(object sender, EventArgs e)
{
_client = new Auth0Client(new Auth0ClientOptions
{
Domain = "{DOMAIN}",
ClientId = "{CLIENT_ID}",
Scope = "openid profile"
});
var loginResult = await _client.LoginAsync();
var sb = new StringBuilder();
if (loginResult.IsError)
{
sb.AppendLine("An error occurred during login:");
sb.AppendLine(loginResult.Error);
Hello @zulfiqar ,
Thank you for the reply!
I ended up using:
_auth0Client = new Auth0Client(new Auth0ClientOptions
{
Domain = AuthenticationConfig.Domain,
ClientId = AuthenticationConfig.ClientId,
Scope = “openid offline_access”
});
This returns a refresh token, which I then re-use when needed by:
var refreshTokenResult = await _auth0Client.RefreshTokenAsync(“…”);
It seems to do the trick, I hope this is the proper way to apply this. Open to any suggestions.
Thanks
1 Like
system
Closed
August 30, 2019, 11:42am
4
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.