当前位置: 首页>>代码示例>>C#>>正文


C# MobileServices.MobileServiceUser类代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.MobileServices.MobileServiceUser的典型用法代码示例。如果您正苦于以下问题:C# MobileServiceUser类的具体用法?C# MobileServiceUser怎么用?C# MobileServiceUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MobileServiceUser类属于Microsoft.WindowsAzure.MobileServices命名空间,在下文中一共展示了MobileServiceUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoginWithCookie

        public static bool LoginWithCookie()
        {
            PasswordCredential credential = null;

            try
            {
                // Try to get an existing credential from the vault.
                credential = vault.FindAllByResource(provider).FirstOrDefault();
            }
            catch (Exception)
            {
                // When there is no matching resource an error occurs, which we ignore.
            }

            if (credential != null)
            {
                // Create a user from the stored credentials.
                user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                // Set the user from the stored credentials.
                App.MobileService.CurrentUser = user;

                // Consider adding a check to determine if the token is 
                // expired, as shown in this post: http://aka.ms/jww5vp.

                return true;
            }

            return false;
        }
开发者ID:avisprince,项目名称:UniversalTodoApp,代码行数:32,代码来源:AuthenticationHelper.cs

示例2: AuthenticateAsync

        public async void AuthenticateAsync()
        {
            while (_user == null)
            {
                string message;
                try
                {
                    //_user = await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.Twitter);
                    // Temporary just used fixed user
                    _user = new MobileServiceUser("SonsOfAnarchy");
                    message = $"You are now signed in - {_user.UserId}";
                }
                catch (InvalidOperationException)
                {
                    message = "You must log in. Login Required";
                }

                var dialog = new MessageDialog(message);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();

                await InitLocalStoreAsync(); // offline sync
                await RefreshTodoItems();
            }
        }
开发者ID:AleksanderGondek,项目名称:GUT_Mobile-Applications,代码行数:25,代码来源:MainPage.cs

示例3: Authenticate

        private async System.Threading.Tasks.Task Authenticate()
        {
            while (user == null)
            {
                string message;
                try
                {
                    user = await App.MobileService
                        .LoginAsync(MobileServiceAuthenticationProvider.Twitter);
                    //user = new MobileServiceUser("Twitter:32533776");
                    //user.MobileServiceAuthenticationToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6MH0.eyJleHAiOjEzNjIxOTcwMDEuNDk3LCJpc3MiOiJ1cm46bWljcm9zb2Z0OndpbmRvd3MtYXp1cmU6enVtbyIsInZlciI6MSwiYXVkIjoiVHdpdHRlciIsInVpZCI6IlR3aXR0ZXI6MzI1MzM3NzYiLCJ1cm46bWljcm9zb2Z0OmNyZWRlbnRpYWxzIjoiU3U5MnFWZlhYaWZjdWhkOE1DU1paZnBUTitFZmttK1NZVDhOcmJzK0FONEc0c1J6WmE1TnoxeUpoaWVYUnFZLzJuUHBQR1FHRTA1dlNzOHpTc2w4QytobWJoQWFGTGRsVTJBVUNkWVpGTGZyY2ZTV0tmUHZuaTMzK1RpTUN3R2QwMFRJdE84RVBrUkZDS2RmTjJEbUVSSGlYUWhQZzhSRnVna1NjdE01OVZyaGVFUjNlNmQ1NEwyZHh1azVyKzE3cy9JV0xVUVdTTk5HdXZDTUlPYThYMG1jSy82MDJQYlFTRFk3czJjYjFiST0ifQ.iU6jzc8Um8skzKqlj97g7YWqZL0Amy9eNFenkMRTFkU";
                    //App.MobileService.CurrentUser = user; 
                    message = string.Format("You are now logged in - {0} with Auth Token {1}", user.UserId, user.MobileServiceAuthenticationToken);

                }
                catch (InvalidOperationException)
                {
                    message = "You must log in. Login Required";
                }

                var dialog = new MessageDialog(message);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
        }
开发者ID:dotnetcurry,项目名称:zumo-authentication-win8,代码行数:25,代码来源:MainPage.xaml.cs

示例4: Authenticate

        private async System.Threading.Tasks.Task Authenticate()
        {
            #region 04_01 Cache Logon
            //PasswordCredential passwordCredential = LogonCacher.GetCredential();
            //if (passwordCredential != null)
            //{
            //    App.MobileService.CurrentUser = new MobileServiceUser(passwordCredential.UserName);
            //    App.MobileService.CurrentUser.MobileServiceAuthenticationToken = passwordCredential.Password;
            //    user = App.MobileService.CurrentUser;
            //}
            #endregion 04_01 Cache Logon

            while (user == null)
            {
                string message;
                try
                {
                    user = await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
                    message = string.Format("You are now logged in - {0}", user.UserId);
                }
                catch (Exception exception)
                {
                    message = "You must log in. Login Required";
                }

                var dialog = new MessageDialog(message);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }

            #region 04_01 Cache Logon
            LogonCacher.SaveCredential(App.MobileService.CurrentUser.UserId, App.MobileService.CurrentUser.MobileServiceAuthenticationToken); 
            #endregion 04_01 Cache Logon

        }
开发者ID:RobertEichenseer,项目名称:RobEichMobileService,代码行数:35,代码来源:MainPage.xaml.cs

示例5: AuthenticateUser

 public void AuthenticateUser(User user)
 {
     CurrentUser = new MobileServiceUser(user.UserId)
     {
         MobileServiceAuthenticationToken = user.AuthToken
     };
 }
开发者ID:PankajbAgarwal,项目名称:ScorePredictForms,代码行数:7,代码来源:AzureMobileServiceClient.cs

示例6: AuthenticateAsync

        // Log the user in with specified provider (Microsoft Account or Facebook)
        private async Task AuthenticateAsync()
        {
            // Use the PasswordVault to securely store and access credentials.
            PasswordVault vault = new PasswordVault();
            PasswordCredential credential = null;

            try
            {
                // Try to get an existing credential from the vault.
                credential = vault.FindAllByResource(provider).FirstOrDefault();
            }
            catch (Exception)
            {
                // do nothing
            }

            if (credential != null)
            {
                // Create a user from the stored credentials.
                user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                // Set the user from the stored credentials.
                App.MobileService.CurrentUser = user;

                try
                {
                    // Try to return an item now to determine if the cached credential has expired.
                    await App.MobileService.GetTable<Event>().Take(1).ToListAsync();
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        // Remove the credential with the expired token.
                        vault.Remove(credential);
                        credential = null;
                    }
                }
            }
            else
            {
                try
                {
                    // Login with the identity provider.
                    user = await App.MobileService.LoginAsync(provider);

                    // Create and store the user credentials.
                    credential = new PasswordCredential(provider,
                        user.UserId, user.MobileServiceAuthenticationToken);
                    vault.Add(credential);
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    Debug.WriteLine(ex.StackTrace);
                }
            }
        }
开发者ID:DXID,项目名称:evenue,代码行数:60,代码来源:LoginPage.xaml.cs

示例7: LoginToken

 public LoginToken(MobileServiceUser user, MobileServiceAuthenticationProvider provider)
 {
     if (user != null && !string.IsNullOrWhiteSpace(user.MobileServiceAuthenticationToken))
     {
         User = user;
     }
     Provider = provider;
 }
开发者ID:rprouse,项目名称:IdeaTrackr-v1,代码行数:8,代码来源:LoginToken.cs

示例8: CacheAuthToken

        public static void CacheAuthToken(MobileServiceUser user)
        {
            var account = new Account(user.UserId);
            account.Properties.Add(TokenKeyName, user.MobileServiceAuthenticationToken);
            GetAccountStore().Save(account, App.AppName);

            Debug.WriteLine($"Cached auth token: {user.MobileServiceAuthenticationToken}");
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:8,代码来源:AuthStore.cs

示例9: CreateUser

        public void CreateUser()
        {
            string id = "qwrdsjjjd8";
            MobileServiceUser user = new MobileServiceUser(id);
            Assert.AreEqual(id, user.UserId);

            new MobileServiceUser(null);
            new MobileServiceUser("");
        }
开发者ID:TroyBolton,项目名称:azure-mobile-services,代码行数:9,代码来源:ZumoUser.Test.cs

示例10: UploadChannel

        /// <summary>
        /// Registers for push notifications.
        /// </summary>

        public async static Task UploadChannel(MobileServiceUser user)
        {
            channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
    
            await App.mobileClient.GetPush().RegisterNativeAsync(channel.Uri , new string[] { user.UserId });

            if (channel != null)
            {
                channel.PushNotificationReceived += OnPushNotificationReceived;
            }
        }
开发者ID:fellipetenorio,项目名称:mobile-services-samples,代码行数:15,代码来源:push.register.cs

示例11: AuthenticateAsync

		private async System.Threading.Tasks.Task AuthenticateAsync(String provider) {
			string message;

			// Use the PasswordVault to securely store and access credentials.
			PasswordVault vault = new PasswordVault();
			PasswordCredential credential = null;

			while (credential == null) {
				try {
					// Try to get an existing credential from the vault.
					credential = vault.FindAllByResource(provider).FirstOrDefault();
				} catch (Exception) {
					// When there is no matching resource an error occurs, which we ignore.
				}

				if (credential != null) {
					// Create a user from the stored credentials.
					_user = new MobileServiceUser(credential.UserName);
					credential.RetrievePassword();
					_user.MobileServiceAuthenticationToken = credential.Password;

					// Set the user from the stored credentials.
					App.MobileService.CurrentUser = _user;

					try {
						// Try to return an item now to determine if the cached credential has expired.
						await App.MobileService.GetTable<TrainingItem>().Take(1).ToListAsync();
					} catch (MobileServiceInvalidOperationException ex) {
						if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized) {
							// Remove the credential with the expired token.
							vault.Remove(credential);
							credential = null;
							continue;
						}
					}
				} else {
					try {
						// Login with the identity provider.
						_user = await App.MobileService.LoginAsync(provider);

						// Create and store the user credentials.
						credential = new PasswordCredential(provider, _user.UserId, _user.MobileServiceAuthenticationToken);
						vault.Add(credential);
					} catch (MobileServiceInvalidOperationException ex) {
						message = "You must log in. Login Required";
					}
				}

				message = string.Format("You are now logged in - {0}", _user.UserId);
				var dialog = new MessageDialog(message);
				dialog.Commands.Add(new UICommand("OK"));
				await dialog.ShowAsync();
			}
		}
开发者ID:fxlemire,项目名称:princeton15,代码行数:54,代码来源:LoginPage.xaml.cs

示例12: Authenticate

        private async System.Threading.Tasks.Task Authenticate()
        {
            while (user == null)
            {
                string message;
                try
                {
                    user = await App.MobileService
                        .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
                    message =
                        string.Format("You are now logged in - {0}", user.UserId);
                    UserID = user.UserId;
                }
                catch (InvalidOperationException)
                {
                    message = "You must log in. Login Required";
                }


                var dialog = new MessageDialog(message);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }


        }
开发者ID:Oboltys,项目名称:NotAlone_W8-1,代码行数:26,代码来源:AddNewEventPage.xaml.cs

示例13: LogoutAsync

		public async Task<bool> LogoutAsync()
		{
			bool success = false;
			try
			{
				if (user != null)
				{
					foreach (var cookie in NSHttpCookieStorage.SharedStorage.Cookies)
					{
						NSHttpCookieStorage.SharedStorage.DeleteCookie(cookie);
					}

					await TodoItemManager.DefaultManager.CurrentClient.LogoutAsync();
					var logoutAlert = new UIAlertView("Authentication", "You are now logged out " + user.UserId, null, "OK", null);
					logoutAlert.Show();
				}
				user = null;
				success = true;
			}
			catch (Exception ex)
			{
				var logoutAlert = new UIAlertView("Logout failed", ex.Message, null, "OK", null);
				logoutAlert.Show();
			}
			return success;
		}
开发者ID:berlamont,项目名称:xamarin-forms-samples,代码行数:26,代码来源:AuthenticationProvider.cs

示例14: Authenticate

    private async System.Threading.Tasks.Task Authenticate()
    {
      while (User == null)
      {
        string message = null;
        try
        {
          User = await App.MobileServiceClient
              .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
        }
        catch (InvalidOperationException)
        {
          message = "You must log in. Login Required";
        }

        if (!string.IsNullOrEmpty(message))
        {
          var dialog = new MessageDialog(message);
          dialog.Commands.Add(new UICommand("OK"));
          await dialog.ShowAsync();
        }
      }

      var user = new User { UserId = User.UserId };
      var userTable = App.MobileServiceClient.GetTable<User>();
      await userTable.InsertAsync(user);

      var channelOperation = await Windows.Networking.PushNotifications.PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
      var userDeviceTable = App.MobileServiceClient.GetTable<UserDevice>();
      var userDevice = new UserDevice { UserId = user.id, DeviceUri = channelOperation.Uri };
      await userDeviceTable.InsertAsync(userDevice);

    }
开发者ID:sseely,项目名称:wams-demo,代码行数:33,代码来源:MainPage.xaml.cs

示例15: Authenticate

        private async System.Threading.Tasks.Task Authenticate(MobileServiceAuthenticationProvider msap)
        {
            try
            {
                user = await App.MobileService.LoginAsync(msap);
            }
            catch
            {

            }
            
            //THIS NEEDS TO BE FIXED TO STORE THE USER'S CREDENTIALs.
            //while (user == null)
            //{
            //    string message;
            //    try
            //    {
            //        user = await App.MobileService.LoginAsync(msap);
            //        message =
            //            string.Format("You are now logged in - {0}", user.UserId);
            //    }
            //    catch (InvalidOperationException)
            //    {
            //        message = "You must log in. Login Required";
            //    }

            //    MessageBox.Show(message);
            //}
        }
开发者ID:jeffblankenburg,项目名称:FanaticApp,代码行数:29,代码来源:LogInScreen.xaml.cs


注:本文中的Microsoft.WindowsAzure.MobileServices.MobileServiceUser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。