Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth0 logout issue #45

Closed
tonyyyrocks39 opened this issue Mar 25, 2019 · 5 comments
Closed

Auth0 logout issue #45

tonyyyrocks39 opened this issue Mar 25, 2019 · 5 comments

Comments

@tonyyyrocks39
Copy link

tonyyyrocks39 commented Mar 25, 2019

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.

@tonyyyrocks39
Copy link
Author

Anybody here ..

@tonyyyrocks39
Copy link
Author

Somehow I made it to work..But still facing problem,Currently when I debug line by line,logout is happening successfully.But when I directly hit F5 logout not working

@beeradmoore
Copy link
Contributor

beeradmoore commented May 13, 2019

Same issue. Because of issue #19 I needed to use the master build, but now I can't log out of the app because of

Missing EndUrl
Parameter name: options

EDIT: If anyone else comes across this problem it is because currently PostLogoutRedirectUri is not set. For us this should be the same thing as RedirectUri. In fact in the code it should be defaulting to this but I am not sure why. The solution is once you create your client to then set this as your PostLogoutRedirectUri.

var client = new Auth0Client(clientOptions);
clientOptions.PostLogoutRedirectUri = clientOptions.RedirectUri;

@damieng
Copy link
Contributor

damieng commented May 14, 2019

Hi @beeradmoore thanks for that workaround.

I'd recommend anyone running into this does the same thing for now - our upcoming branch master...clean-up-browsers is going to do exactly the same thing.

This was referenced May 31, 2019
@damieng
Copy link
Contributor

damieng commented Jun 6, 2019

This now defaults correctly in master and will ship in the next version.

@damieng damieng closed this as completed Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants