本文整理汇总了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;
}
示例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();
}
}
示例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();
}
}
示例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
}
示例5: AuthenticateUser
public void AuthenticateUser(User user)
{
CurrentUser = new MobileServiceUser(user.UserId)
{
MobileServiceAuthenticationToken = user.AuthToken
};
}
示例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);
}
}
}
示例7: LoginToken
public LoginToken(MobileServiceUser user, MobileServiceAuthenticationProvider provider)
{
if (user != null && !string.IsNullOrWhiteSpace(user.MobileServiceAuthenticationToken))
{
User = user;
}
Provider = provider;
}
示例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}");
}
示例9: CreateUser
public void CreateUser()
{
string id = "qwrdsjjjd8";
MobileServiceUser user = new MobileServiceUser(id);
Assert.AreEqual(id, user.UserId);
new MobileServiceUser(null);
new MobileServiceUser("");
}
示例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;
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
//}
}