Hi ,
Currently in my Xamairn.Android I have 2 activities Mainactivity and SignoutActivity.
In my Mainactivity I have a button where when user clicks the button it goes to SignoutActivity.
Here I have implemented the signout codes of Auth0.
Here are the codes-
MainAcitivity-
this.Signout.Click += delegate
{
using (var intent = new Intent(this, typeof(SignOutActivity)))
{
this.StartActivity(intent);
}
};
SignOutAcitivity-
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
this.LogoutAsync();
Finish();
}
public async Task<BrowserResult> LogoutAsync()
{
var clientOptions = new Auth0.OidcClient.Auth0ClientOptions
{
Domain ="",
ClientId = "",
Scope = "openid email offline_access",
Browser = new PlatformWebView()
};
var logoutUrl = "Signout URl";
string redirectUri = "I have proper callback uri";
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("client_id", "random1234");
dictionary.Add("returnTo", clientOptions.RedirectUri);
string endSessionUrl = new RequestUrl(logoutUrl).Create(dictionary);
var logoutRequest = new LogoutRequest();
BrowserResult browserResult = null;
browserResult = await clientOptions.Browser.InvokeAsync(new BrowserOptions(endSessionUrl, redirectUri)
{
Timeout = TimeSpan.FromSeconds((double)logoutRequest.BrowserTimeout),
DisplayMode = logoutRequest.BrowserDisplayMode
});
return browserResult;
}
Platformview-
class PlatformWebView : IBrowser
{
public Task<BrowserResult> InvokeAsync(BrowserOptions options)
{
if (string.IsNullOrWhiteSpace(options.StartUrl))
{
throw new ArgumentException("Missing StartUrl", nameof(options));
}
if (string.IsNullOrWhiteSpace(options.EndUrl))
{
throw new ArgumentException("Missing EndUrl", nameof(options));
}
var tcs = new TaskCompletionSource<BrowserResult>();
void Callback(string response)
{
ActivityMediator.Instance.ActivityMessageReceived -= Callback;
// set result
if (response == "UserCancel")
{
tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.UserCancel });
}
else
{
tcs.SetResult(new BrowserResult
{
Response = response,
ResultType = BrowserResultType.Success
});
}
}
ActivityMediator.Instance.ActivityMessageReceived += Callback;
var uri = Android.Net.Uri.Parse(options.StartUrl);
var intent = new Intent(Intent.ActionView, uri);
intent.AddFlags(ActivityFlags.NoHistory)
.AddFlags(ActivityFlags.NewTask);
Application.Context.StartActivity(intent);
return tcs.Task;
}
}
}
Problem is browser never returns to app,Also I have put a debugger at return browserResult,this debugger also does not hit.Please help me.