xamarin.Auth Canceled By User Error

장주명 41 Reputation points
2021-11-13T12:18:37.417+00:00

I'm working on a project using xamarin.Auth.

148997-screenshot-20211113-205318.jpg

However, if you click the Cancel button or click the close button as shown in the picture, the app will crash.

I just want to take down the page, what should I do!?

here is my Code

public Task LoginWithSNSAsync(SNSProvider provider)  
  
        {  
            try  
            {  
                oAuth2 = OAuth2ProviderFactory.CreateProvider(provider);  
                var authenticator = new OAuth2Authenticator(  
                    oAuth2.ClientId,  
                    oAuth2.ClientSecret,  
                    oAuth2.Scope,  
                    oAuth2.AuthorizationUri,  
                    oAuth2.RedirectUri,  
                    oAuth2.RequestTokenUri,  
                    null,  
                    oAuth2.IsUsingNativeUI);  
                 
  
                  
  
                authenticator.Completed += async (s, e) =>  
                {  
                    if (e.IsAuthenticated)  
                    {  
                        var user = await oAuth2.GetUserInfoAsync(e.Account);  
  
                        AppSettings.User = user;  
  
                        MessagingCenter.Send(user, MessagingCenterEvents.AuthenticationRequested, true);  
                        Debug.WriteLine("Authentication Success");  
                    }  
                };  
                authenticator.Error += (s, e) =>  
                {  
                    Debug.WriteLine("Authentication error: " + e.Message);  
                };  
  
                var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();  
                presenter.Login(authenticator);  
  
            }  
            catch (Exception ex)  
            {  
                Debug.WriteLine("Login Error : " + ex.Message);  
                return Task.FromResult(false);  
            }  
            return Task.FromResult(true);  
        }  
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,376 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,966 Reputation points
    2021-11-15T06:42:46.897+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    I just want to take down the page

    The OnCancelled command can used to hide the dialog, try to call the method in the Error event to perform the work.

       authenticator.Error += (s, e) =>  
       {  
           OAuth2Authenticator auth2 = (OAuth2Authenticator)s;  
           auth2.OnCancelled();  
       };  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.