Exemplo n.º 1
0
        public async Task <bool> LogoutAsync()
        {
            if (!IsInitialized)
            {
                await InitializeAsync();
            }

            bool success = false;

            try
            {
                if (User != null)
                {
                    await MobileService.LogoutAsync();

                    foreach (var user in ADB2CClient.Users)
                    {
                        ADB2CClient.Remove(user);
                    }
                    User = null;

                    Settings.AuthToken = string.Empty;
                    Settings.UserId    = string.Empty;
                    Settings.Role      = string.Empty;

                    success = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(success);
        }
        public async Task <bool> LogoutAsync()
        {
            bool success = false;

            try
            {
                IEnumerable <IAccount> accounts = await ADB2CClient.GetAccountsAsync();

                while (accounts.Any())
                {
                    await ADB2CClient.RemoveAsync(accounts.First());

                    accounts = await ADB2CClient.GetAccountsAsync();
                }

                User = null;

                success = true;
            }
            catch (Exception ex)
            {
                success = false;
                throw ex;
            }
            return(success);
        }
Exemplo n.º 3
0
        public async Task <bool> LogoutAsync()
        {
            bool success = false;

            try
            {
                if (User != null)
                {
                    await AzureService.DefaultService.CurrentClient.LogoutAsync();

                    foreach (var user in ADB2CClient.Users)
                    {
                        ADB2CClient.Remove(user);
                    }
                    AzureService.DefaultService.User = null;
                    User    = null;
                    success = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(success);
        }
Exemplo n.º 4
0
        public async Task <bool> LoginAsync(bool useSilent = false)
        {
            bool success = false;

            try
            {
                AuthenticationResult authenticationResult;

                if (useSilent)
                {
                    authenticationResult = await ADB2CClient.AcquireTokenSilentAsync(
                        Locations.Scopes,
                        GetUserByPolicy(ADB2CClient.Users, Locations.PolicySignUpSignIn),
                        Locations.Authority,
                        false);
                }
                else
                {
                    authenticationResult = await ADB2CClient.AcquireTokenAsync(
                        Locations.Scopes,
                        GetUserByPolicy(ADB2CClient.Users, Locations.PolicySignUpSignIn),
                        App.UiParent);
                }

                if (User == null)
                {
                    var payload = new JObject();
                    if (authenticationResult != null && !string.IsNullOrWhiteSpace(authenticationResult.IdToken))
                    {
                        payload["access_token"] = authenticationResult.IdToken;
                    }

                    User = await AzureService.DefaultService.CurrentClient.LoginAsync(
                        MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
                        payload);

                    success = true;

                    if (success)
                    {
                        await FindUser(authenticationResult, useSilent);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(success);
        }
        public async Task <bool> LoginAsync(bool useSilent = false)
        {
            bool success = false;

            try
            {
                AuthenticationResult   authenticationResult;
                IEnumerable <IAccount> accounts = await ADB2CClient.GetAccountsAsync();

                if (useSilent)
                {
                    authenticationResult = await ADB2CClient.AcquireTokenSilentAsync(
                        Constants.Scopes,
                        accounts.FirstOrDefault());
                }
                else
                {
                    authenticationResult = await ADB2CClient.AcquireTokenAsync(
                        Constants.Scopes,
                        string.Empty,
                        UIBehavior.SelectAccount,
                        string.Empty,
                        App.UiParent);
                }

                if (User == null)
                {
                    var payload = new JObject();
                    if (authenticationResult != null && !string.IsNullOrWhiteSpace(authenticationResult.AccessToken))
                    {
                        payload["access_token"] = authenticationResult.AccessToken;
                    }

                    User = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(
                        MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
                        payload);

                    success = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(success);
        }
Exemplo n.º 6
0
        public async Task <bool> LoginAsync(bool useSilent = false)
        {
            if (!IsInitialized)
            {
                await InitializeAsync();
            }

            bool success = false;

            try
            {
                AuthenticationResult authenticationResult;

                if (useSilent)
                {
                    authenticationResult = await ADB2CClient.AcquireTokenSilentAsync(
                        Constants.Scopes,
                        GetUserByPolicy(ADB2CClient.Users, Constants.PolicySignUpSignIn),
                        Constants.Authority,
                        false);
                }
                else
                {
                    authenticationResult = await ADB2CClient.AcquireTokenAsync(
                        Constants.Scopes,
                        GetUserByPolicy(ADB2CClient.Users, Constants.PolicySignUpSignIn),
                        App.UiParent);
                }

                if (User == null)
                {
                    if (authenticationResult != null && !string.IsNullOrWhiteSpace(authenticationResult.IdToken))
                    {
                        //Read token

                        var tokenClaims = JwtUtility.GetClaims(authenticationResult.IdToken);

                        var sub = tokenClaims["sub"];

                        MobileServiceUser user = new MobileServiceUser(sub.ToString())
                        {
                            MobileServiceAuthenticationToken = authenticationResult.IdToken
                        };

                        MobileService.CurrentUser = user;

                        User = user;

                        var profileUser = await UserStore.GetProfileAsync(authenticationResult.IdToken);

                        // CacheToken
                        CacheToken(user, profileUser);

                        success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(success);
        }