• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# MobileServices.MobileServiceUser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

        private void ExecuteDoAfterSuccessfulLogin(MobileServiceUser user)
        {
            // move to another view
            this.loggedInUserService.LoggedInUser = user;

            // don't move on if user was null
            if (this.loggedInUserService.LoggedInUser == null) {
                return;
            }

            this.ShowViewModel<UserSelectionViewModel> ();
        }
开发者ID:roylanceMichael,项目名称:GetFit,代码行数:12,代码来源:UserLoginViewModel.cs


示例13: AuthenticateAsync

 // Define a method that performs the authentication process
 // using a Twitter sign-in. 
 private async Task<bool> AuthenticateAsync()
 {
     string message;
     bool success = false;
     // This sample uses the Facebook provider.
     var provider = "Twitter";
     // 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)
     {
         // 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.
         success = true;
         message = string.Format("Cached credentials for user - {0}", user.UserId);
     }
     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);
             success = true;
         }
         catch (MobileServiceInvalidOperationException)
         {
             message = "You must log in. Login Required";
         }
     }
     return success;
 }
开发者ID:TomMurphyDev,项目名称:AzureMediaStreaming,代码行数:53,代码来源:MainPage.cs


示例14: AuthenticateAsync

        public async Task<bool> AuthenticateAsync()
        {
            this.CurrentUserId = null;

            PasswordCredential credential;

            if (TryGetCachedCredential(out credential))
            {
                var user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                this.serviceClient.CurrentUser = user;

                if (await HasTokenExpired())
                {
                    vault.Remove(credential);
                }
                else
                {
                    this.CurrentUserId = user.UserId;
                    this.IsAuthenticated = true;
                }
            }

            if (!this.IsAuthenticated)
            {
                try
                {
                    var user = await this.serviceClient
                        .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);

                    credential = new PasswordCredential(
                        MobileServiceAuthenticationProvider.MicrosoftAccount.ToString(),
                        user.UserId,
                        user.MobileServiceAuthenticationToken);
                    vault.Add(credential);

                    this.CurrentUserId = user.UserId;
                    this.IsAuthenticated = true;
                }
                catch (MobileServiceInvalidOperationException)
                {
                    this.IsAuthenticated = false;
                }
            }

            return this.IsAuthenticated;
        }
开发者ID:kieranlynam,项目名称:LondonCoffee,代码行数:49,代码来源:AzureIdentityService.cs


示例15: TryAuthenticateSilently

        public static async Task<bool> TryAuthenticateSilently(bool useCachedCredentials = true)
        {
            MobileServiceUser user = null;

            var vault = new PasswordVault();

            PasswordCredential savedCredentials = null;

            if (useCachedCredentials && LegacyUserId.Value != null)
            {
                try
                {
                    savedCredentials = vault.FindAllByResource(ProviderId).FirstOrDefault();
                }
                catch (Exception)
                {
                    // No credentials found.
                }
            }

            if (savedCredentials != null)
            {
                user = new MobileServiceUser(savedCredentials.UserName)
                {
                    MobileServiceAuthenticationToken = vault.Retrieve(ProviderId, savedCredentials.UserName).Password
                };

                MobileService.Client.CurrentUser = user;
            }

            if (user == null)
            {
                try
                {
                    user = await DoLoginAsync(CredentialPromptType.DoNotPrompt);
                }
                catch (Exception)
                {
                    // Do nothing
                }

                if (user != null)
                {
                    vault.Add(new PasswordCredential(ProviderId, user.UserId, user.MobileServiceAuthenticationToken));
                }
            }

            return user != null;
        }
开发者ID:pglazkov,项目名称:Linqua,代码行数:49,代码来源:SecurityManager.cs


示例16: 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


示例17: 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


示例18: 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


示例19: 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


示例20: Authenticate

        private async Task Authenticate(MobileServiceAuthenticationProvider provider)
        {
           

                try
                {
                    WAMSRepositoryService service = Mvx.Resolve<IRepositoryService>() as WAMSRepositoryService;
                    user = await service.MobileService
                        .LoginAsync(this, provider);


                }
                catch (InvalidOperationException e)
                {

                }


                var vm = ViewModel as AuthViewModel;

                if (user != null)
                {

                    vm.CreateUserCommand.Execute(user);
                }
                else
                {
                    vm.BackCommand.Execute(null);
                }
         
        }
开发者ID:aocsa,项目名称:CInca,代码行数:31,代码来源:AuthView.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Test.LongIdType类代码示例发布时间:2022-05-26
下一篇:
C# MobileServices.MobileServiceClient类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap