本文整理汇总了C#中MobileServiceAuthenticationProvider类的典型用法代码示例。如果您正苦于以下问题:C# MobileServiceAuthenticationProvider类的具体用法?C# MobileServiceAuthenticationProvider怎么用?C# MobileServiceAuthenticationProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MobileServiceAuthenticationProvider类属于命名空间,在下文中一共展示了MobileServiceAuthenticationProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
private async Task Login(MobileServiceAuthenticationProvider provider)
{
var user = await _authenticationService.Login(provider);
var userName = await GetIsOauthUserRegistered (user.UserId);
await _databaseService.SaveCurrentUserAsync(new User { UserName = userName } );
await _databaseService.DeleteAllScheduledConferencesAsync ();
var conferenceDtos = await _remoteConferenceService.LoadScheduledConferencesAsync (userName);
foreach (var conferenceDto in conferenceDtos) {
var dto = conferenceDto;
dto.IsAddedToSchedule = true;
var conference = await TaskEx.Run (() => Mapper.Map<Conference> (dto));
await _databaseService.SaveConferenceAsync (conference);
foreach (var sessionDto in dto.Sessions)
{
SessionDto dto1 = sessionDto;
var session = await TaskEx.Run(() => Mapper.Map<Session>(dto1));
session.ConferenceId = conference.Id;
await _databaseService.SaveSessionAsync(session);
foreach (var speakerDto in sessionDto.Speakers)
{
SpeakerDto speakerDto1 = speakerDto;
var speaker = await TaskEx.Run(() => Mapper.Map<Speaker>(speakerDto1));
speaker.SessionId = session.Id;
await _databaseService.SaveSpeakerAsync(speaker);
}
}
}
ShowViewModel<ConferencesTabViewModel> ();
}
示例2: LoginAsync
public async Task<MobileServiceUser> LoginAsync(MobileServiceClient client, MobileServiceAuthenticationProvider provider)
{
try
{
var window = UIKit.UIApplication.SharedApplication.KeyWindow;
var root = window.RootViewController;
if(root != null)
{
var current = root;
while(current.PresentedViewController != null)
{
current = current.PresentedViewController;
}
Settings.LoginAttempts++;
var user = await client.LoginAsync(current, provider);
Settings.AuthToken = user?.MobileServiceAuthenticationToken ?? string.Empty;
Settings.UserId = user?.UserId ?? string.Empty;
return user;
}
}
catch(Exception e)
{
e.Data["method"] = "LoginAsync";
Xamarin.Insights.Report(e);
}
return null;
}
示例3: 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);
}
}
示例4: loginAsync
public async void loginAsync(MobileServiceAuthenticationProvider provider){
while(! await DependencyService.Get<IAuthenticate> ().loginAsync (MobileServiceAuthenticationProvider.Twitter)){
await DisplayAlert ("Login Fail", "Please try to login again", "OK");
}
await DisplayAlert ("Login", "Logged in successfully as: " +App.MobileService.CurrentUser.UserId, "OK");
await Navigation.PushAsync (new Profile("twitter"));
}
示例5: TestRefreshUserAsync
/// <summary>
/// Tests the <see cref="MobileServiceClient.RefreshUserAsync"/> functionality on the platform.
/// </summary>
/// <param name="provider">
/// The provider with which to login.
/// </param>
/// <returns>
/// The UserId and MobileServiceAuthentication token obtained from logging in.
/// </returns>
public static async Task<string> TestRefreshUserAsync(MobileServiceAuthenticationProvider provider)
{
string result;
switch (provider)
{
case MobileServiceAuthenticationProvider.MicrosoftAccount:
result = await TestMicrosoftAccountRefreshUserAsync();
break;
case MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory:
result = await TestAADRefreshUserAsync();
break;
case MobileServiceAuthenticationProvider.Google:
result = await TestGoogleRefreshUserAsync();
break;
case MobileServiceAuthenticationProvider.Facebook:
result = await TestFacebookRefreshUserAsync();
break;
case MobileServiceAuthenticationProvider.Twitter:
result = await TestTwitterRefreshUserAsync();
break;
default:
result = "MobileServiceAuthenticationProvider is not recognized.";
break;
}
return result;
}
示例6: 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);
//}
}
示例7: DoLoginAsync
private async Task DoLoginAsync(MobileServiceAuthenticationProvider provider)
{
MobileServiceUser user;
try
{
user = await DependencyService.Get<IMobileClient>().LoginAsync(provider);
App.AuthenticatedUser = user;
System.Diagnostics.Debug.WriteLine("Authenticated with user: " + user.UserId);
#if __DROID__
Droid.GcmService.RegisterWithMobilePushNotifications();
#elif __IOS__
iOS.AppDelegate.IsAfterLogin = true;
await iOS.AppDelegate.RegisterWithMobilePushNotifications();
#elif __WP__
ContosoMoments.WinPhone.App.AcquirePushChannel(App.MobileService);
#endif
//Navigation.InsertPageBefore(new ImagesList(), this);
Navigation.InsertPageBefore(new AlbumsListView(), this);
await Navigation.PopAsync();
}
catch (InvalidOperationException ex)
{
if (ex.Message.Contains("Authentication was cancelled"))
{
messageLabel.Text = "Authentication cancelled by the user";
}
}
catch (Exception ex)
{
messageLabel.Text = "Authentication failed";
}
}
示例8: AuthenticateAsync
/// <summary>
/// Starts the authentication process.
/// </summary>
/// <param name="provider">The provider to authenticate with.</param>
public async Task AuthenticateAsync(MobileServiceAuthenticationProvider provider)
{
try
{
var vault = new PasswordVault();
// Login with the identity provider.
var user = await AzureAppService.Current
.LoginAsync(provider);
// Create and store the user credentials.
var credential = new PasswordCredential(provider.ToString(),
user.UserId, user.MobileServiceAuthenticationToken);
vault.Add(credential);
}
catch (InvalidOperationException invalidOperationException)
{
if (invalidOperationException.Message
.Contains("Authentication was cancelled by the user."))
{
throw new AuthenticationCanceledException("Authentication canceled by user",
invalidOperationException);
}
throw new AuthenticationException("Authentication failed", invalidOperationException);
}
catch (Exception e)
{
throw new AuthenticationException("Authentication failed", e);
}
}
示例9: Login
private async void Login(MobileServiceAuthenticationProvider provider)
{
var client = new MobileServiceClient(this.uriEntry.Value, this.keyEntry.Value);
var user = await client.LoginAsync(this, provider);
var alert = new UIAlertView("Welcome", "Your userId is: " + user.UserId, null, "OK");
alert.Show();
}
示例10: LoginToken
public LoginToken(MobileServiceUser user, MobileServiceAuthenticationProvider provider)
{
if (user != null && !string.IsNullOrWhiteSpace(user.MobileServiceAuthenticationToken))
{
User = user;
}
Provider = provider;
}
示例11: MobileServiceTokenAuthentication
/// <summary>
/// Instantiates a new instance of <see cref="MobileServiceTokenAuthentication"/>.
/// </summary>
/// <param name="client">
/// The client.
/// </param>
/// <param name="provider">
/// The authentication provider.
/// </param>
/// <param name="token">
/// The token.
/// </param>
public MobileServiceTokenAuthentication(MobileServiceClient client, MobileServiceAuthenticationProvider provider, JObject token)
:base(client, provider)
{
Debug.Assert(client != null, "client should not be null.");
Debug.Assert(token != null, "token should not be null.");
this.client = client;
this.token = token;
}
示例12: LoginAsync
/// <summary>
/// Log a user into a Mobile Services application given a provider name and optional token object.
/// </summary>
/// <param name="provider" type="MobileServiceAuthenticationProvider">
/// Authentication provider to use.
/// </param>
/// <param name="client">
/// The <see cref="MobileServiceClient"/> to login with.
/// </param>
/// <param name="useSingleSignOn">
/// Indicates that single sign-on should be used. Single sign-on requires that the
/// application's Package SID be registered with the Windows Azure Mobile Service, but it
/// provides a better experience as HTTP cookies are supported so that users do not have to
/// login in everytime the application is launched.
/// </param>
/// <returns>
/// Task that will complete when the user has finished authentication.
/// </returns>
public static Task<MobileServiceUser> LoginAsync(this IMobileServiceClient client, MobileServiceAuthenticationProvider provider, bool useSingleSignOn)
{
if(!useSingleSignOn)
{
return client.LoginAsync(provider);
}
MobileServiceSingleSignOnAuthentication auth = new MobileServiceSingleSignOnAuthentication(client, provider);
return auth.LoginAsync();
}
示例13: LoginAsync
public Task<MobileServiceUser> LoginAsync(IMobileServiceClient client, MobileServiceAuthenticationProvider provider, IDictionary<string, string> parameters = null)
{
try
{
return client.LoginAsync(Forms.Context, provider, parameters);
}
catch { }
return null;
}
示例14: CreateLoginTest
private static ZumoTest CreateLoginTest(MobileServiceAuthenticationProvider provider, bool useSingleSignOn)
{
string testName = string.Format("Login with {0}{1}", provider, useSingleSignOn ? " (using single sign-on)" : "");
return new ZumoTest(testName, async delegate(ZumoTest test)
{
var client = ZumoTestGlobals.Instance.Client;
var user = await client.LoginAsync(provider, useSingleSignOn);
test.AddLog("Logged in as {0}", user.UserId);
return true;
});
}
示例15: LoginAsync
public async Task<MobileServiceUser> LoginAsync(MobileServiceAuthenticationProvider provider)
{
try
{
return await mobileService.LoginAsync(provider);
}
catch (InvalidOperationException)
{
return null;
}
}