Exemplo n.º 1
0
        public Task BeginLogoutAsync(Action <LogoutParameters> configureParameters = null)
        {
            return(HandleErrors(nameof(BeginLogoutAsync), async() =>
            {
                if (!SessionIsValid)
                {
                    await UpdateUserState(null, true, true);
                }
                if (UserState == null)
                {
                    return;
                }

                await InitAsync(true); //Needed for redirect callback

                var idToken = UserState.IdToken;

                var request = await LogoutClient.CreateLogoutRequest(idToken, configureParameters);
                var browserRequest = LogoutClient.CreateBrowserRequest(request);

                await UpdateUserState(null, false, true);

                if (request.Parameters.InteractionType.IsPopup())
                {
                    UserChanged?.Invoke(null);
                }
                await Helper.StartFlow(browserRequest);
            }));
        }
Exemplo n.º 2
0
        public Task BeginLogoutAsync(Action <LogoutParameters> configureParameters = null)
        {
            return(HandleErrors(nameof(BeginLogoutAsync), async() =>
            {
                if (!SessionIsValid)
                {
                    await UpdateUserState(null, true, true);
                }
                if (UserState == null)
                {
                    return;
                }

                await InitAsync(true); //Needed for redirect callback

                var idToken = UserState.IdToken;

                var request = await LogoutClient.CreateLogoutRequest(idToken, configureParameters);

                await UpdateUserState(null, true, true);

                if (request.Parameters.InteractionType.IsRedirect())
                {
                    UriHelper.NavigateTo(request.Url);
                }
                else
                {
                    UserChanged?.Invoke(User);
                    await Interop.OpenPopup(LogoutClient.CreatePopupRequest(request));
                }
            }));
        }
Exemplo n.º 3
0
 public Task CompleteLogoutAsync(string url)
 {
     return(HandleErrors(nameof(CompleteLogoutAsync), async() =>
     {
         await InitAsync(true); //Needed for redirect callback
         await LogoutClient.ParseResponse(url);
     }));
 }
Exemplo n.º 4
0
        public Task CompleteLogoutAsync(string url, InteractionType interactionType)
        {
            return(HandleErrors(nameof(CompleteLogoutAsync), async() =>
            {
                await InitAsync(true); //Needed for redirect callback
                var requestState = await LogoutClient.ParseResponse(url);

                if (interactionType == InteractionType.Popup)
                {
                    if (Settings.PostAuthenticationPopup != null)
                    {
                        await Settings.PostLogoutPopup(User, requestState.Data, ServiceProvider);
                    }
                }
                else
                {
                    if (Settings.PostAuthenticationRedirect != null)
                    {
                        await Settings.PostLogoutRedirect(User, requestState.Data, ServiceProvider);
                    }
                }
            }));
        }
Exemplo n.º 5
0
        public async Task <Tuple <bool, string> > SignOutAsync()
        {
            try
            {
                LoggerService.Instance.Log("Account.SignOutAsync...");
                IsLoading = true;
                var error   = string.Empty;
                var success = false;

                if (SignedIn)
                {
                    var email = string.Empty;
                    if (!string.IsNullOrEmpty(UserInfo.Email))
                    {
                        email = UserInfo.Email.ToLower();
                    }

                    var name = string.Empty;
                    if (!string.IsNullOrEmpty(UserInfo.Name))
                    {
                        name = UserInfo.Name.ToLower();
                    }

#if _IOS_
                    var notificationToken = RemoteNotificationsService.Instance.GetTokenValue();
                    if (!string.IsNullOrEmpty(notificationToken))
                    {
                        var notificationType = RemoteNotificationsService.Instance.GetTokenType();
                        await NotificationClient.RemoveDevice(notificationType, notificationToken);
                    }
#endif
                    var response = await LogoutClient.Logout();

                    if (response != null)
                    {
                        if (response.Success)
                        {
                            SharedSettingsService.Instance.SetBoolValue("AutoDownloadDBCreated" + email, false);
                            await(Application.Current.MainPage.BindingContext as Cloud).Logout();
                            OnPropertyChanged("SignedIn");
                            success = true;
                        }
                        else
                        {
                            error = response.ErrorMessageClean;
                        }
                    }
                    else
                    {
                        error = "There was an error logging out";
                    }
                }
                else
                {
                    error = "Please log in before attempting to log out";
                }

                if (!string.IsNullOrEmpty(error))
                {
                    LoggerService.Instance.Log("ERROR: Account.SignOutAsync: " + error);
                }
                else
                {
                    LoggerService.Instance.Log("Account.SignOutAsync: success");
                }

                OnPropertyChanged("SignedIn");
                return(Tuple.Create(success, error));
            }
            finally
            {
                IsLoading = false;
            }
        }