Example #1
0
        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);
                }
         
        }
 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();
 }
Example #3
0
        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: "******"Authentication was cancelled"))
                {
                    messageLabel.Text = "Authentication cancelled by the user";
                }
            }
            catch (Exception ex)
            {
                messageLabel.Text = "Authentication failed";
            }
        }
        /// <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);
            }
        }
Example #5
0
		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> ();
		}
 /// <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;
 }
Example #7
0
        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;
        }
        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);
            //}
        }
Example #9
0
		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"));
		}
Example #10
0
 public LoginToken(MobileServiceUser user, MobileServiceAuthenticationProvider provider)
 {
     if (user != null && !string.IsNullOrWhiteSpace(user.MobileServiceAuthenticationToken))
     {
         User = user;
     }
     Provider = provider;
 }
        /// <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;
        }
        public Task<MobileServiceUser> LoginAsync(IMobileServiceClient client, MobileServiceAuthenticationProvider provider, IDictionary<string, string> parameters = null)
        {
            try
            {
                return client.LoginAsync(Forms.Context, provider, parameters);
            }
            catch { }

            return null;
        }
        /// <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();
        }
 public async Task<MobileServiceUser> LoginAsync(MobileServiceAuthenticationProvider provider)
 {
     try
     {
         return await mobileService.LoginAsync(provider);
     }
     catch (InvalidOperationException)
     {
         return null;
     }
 }
 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;
     });
 }
Example #16
0
 private async Task Login(MobileServiceAuthenticationProvider provider)
 {
     try
     {
         var user = await MobileService.LoginAsync(provider);
         AddToDebug("Logged in as {0}", user.UserId);
     }
     catch (Exception ex)
     {
         this.AddToDebug("Error: {0}", ex);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileServiceAuthentication"/> class.
        /// </summary>
        /// <param name="client">
        /// The <see cref="MobileServiceClient"/> associated with this 
        /// MobileServiceLogin instance.
        /// </param>
        /// <param name="provider">
        /// The <see cref="MobileServiceAuthenticationProvider"/> used to authenticate.
        /// </param>
        public MobileServiceAuthentication(IMobileServiceClient client, MobileServiceAuthenticationProvider provider)
        {
            Debug.Assert(client != null, "client should not be null.");

            this.Client = client;
            this.Provider = provider;

            string providerName = this.Provider.ToString().ToLower();

            this.StartUri = new Uri(this.Client.ApplicationUri, MobileServiceAuthentication.LoginAsyncUriFragment + "/" + providerName);
            this.EndUri = new Uri(this.Client.ApplicationUri, MobileServiceAuthentication.LoginAsyncDoneUriFragment);
        }
		public async Task<bool> loginAsync (MobileServiceAuthenticationProvider provider){
			string message;
			try{
				await App.MobileService.LoginAsync (Forms.Context,provider);
				return true;
			}
			catch(InvalidOperationException){
				return false;
			}
			catch(Exception e){
				return false;
			}
		}
Example #19
0
        private async Task LoginAsync(MobileServiceAuthenticationProvider provider)
        {
            var user = await authentication.LoginAsync(provider);

            if (user == null)
            {

            }
            else
            {
                applicationNavigation.ToCurrentExpenses();
            }
        }
		public async Task<bool> loginAsync (MobileServiceAuthenticationProvider provider){
			string message;
			try{
				var view = UIApplication.SharedApplication.KeyWindow.RootViewController;
				await App.MobileService.LoginAsync (view, provider);
				return true;
			}
			catch(InvalidOperationException){
				return false;
			}
			catch(Exception e){
				return false;
			}
		}
        /// <summary>
        /// Tests the <see cref="MobileServiceClient.LoginAsync"/> functionality on the platform.
        /// </summary>
        /// <param name="provider">The provider with which to login.
        /// </param>
        /// <param name="useProviderStringOverload">Indicates if the call to <see cref="MobileServiceClient.LoginAsync"/>
        /// should be made with the overload where the provider is passed as a string.
        /// </param>
        /// <returns>The UserId and MobileServiceAuthentication token obtained from logging in.</returns>
        public static async Task<string> TestLoginAsync(MobileServiceAuthenticationProvider provider, bool useProviderStringOverload)
        {
            MobileServiceUser user;
            if (useProviderStringOverload)
            {
                user = await client.LoginAsync(provider.ToString());
            }
            else
            {
                user = await client.LoginAsync(provider);
            }

            return string.Format("UserId: {0} Token: {1}", user.UserId, user.MobileServiceAuthenticationToken);
        }
		public async Task AuthenticateAsync(MobileServiceAuthenticationProvider provider)
		{
			try
			{
				await this.MobileService.LoginAsync(provider);

				await this.navigation.PopModalAsync();
			}
			catch (InvalidOperationException)
			{
				// TODO: Show error
				//await this.OnShowErrorAsync?.Invoke("Authentication failed. Please try again.");
			}
		}
Example #23
0
		private async Task AuthenticateAsync(MobileServiceAuthenticationProvider provider)
		{
			try
			{
				await MobileService.Instance.LoginAsync(this, provider);

				var intent = new Intent(this, typeof(MainActivity));
				StartActivity(intent);
			}
			catch (InvalidOperationException)
			{
				// TODO: Show an error;
			}
		}
		private async Task AuthenticateAsync(MobileServiceAuthenticationProvider provider)
		{
			try
			{
				await MobileService.Instance.LoginAsync(this, provider);

				this.PerformSegue("ToList", this);
			}
			catch (InvalidOperationException)
			{
				// TODO: Show an error;
				var blah = 0;
			}
		}
Example #25
0
        public async Task<MobileServiceUser> LoginAsync(MobileServiceAuthenticationProvider provider)
        {
            //MobileServiceUser user = null;

            //try
            //{
            //    user = await App.MobileService.LoginAsync(Forms.Context, provider);
            //}
            //catch (Exception ex)
            //{
            //}

            //return user;
            return await App.MobileService.LoginAsync(Forms.Context, provider);
        }
        public Task<MobileServiceUser> LoginAsync(IMobileServiceClient client, MobileServiceAuthenticationProvider provider, IDictionary<string, string> parameters = null)
        {
            try
            {

				return client.LoginAsync(GetController(), provider, parameters);
                
            }
            catch (Exception e)
            {
                e.Data["method"] = "LoginAsync";
            }

            return null;
        }
        private static async Task<MobileServiceUser> Authenticate(MobileServiceAuthenticationProvider provider)
        {
            try
            {
#if __IOS__
                    return await Client.LoginAsync(UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController, provider);
#elif WINDOWS_PHONE
                return await Client.LoginAsync(provider);
#else
                return await Client.LoginAsync(Xamarin.Forms.Forms.Context, provider);
#endif
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Example #28
0
 private async System.Threading.Tasks.Task Autenticar(MobileServiceAuthenticationProvider provider)
 {
     while (user == null)
     {
         string mensagem = string.Empty;
         try
         {
             user = await App.MobileService.LoginAsync(provider);
             mensagem = string.Format("Usuário logado em: {0}", user.UserId);
         }
         catch(InvalidOperationException ex)
         {
             mensagem = "Usuário não Logado.";
         }
         MessageBox.Show(mensagem);
     }
 }
 private async Task AuthenticateAsync(MobileServiceAuthenticationProvider provider)
 {
    
     string message=null;
     try
     {
         currentUser = await App.MobileService
             .LoginAsync(provider);
        
     }
     catch (InvalidOperationException ioe)
     {
         currentUser = null;
         message = "ERROR : " + ioe.Message;
     }
     if (!string.IsNullOrEmpty(message))
         await new MessageDialog(message, "ERREUR").ShowAsync();
 }
Example #30
0
        public async Task<MobileServiceUser> LoginAsync(MobileServiceAuthenticationProvider provider)
        {
            var view = UIApplication.SharedApplication.KeyWindow.RootViewController;

            //MobileServiceUser user = null;

            //try
            //{
            //    UIViewController v = (UIViewController)view;
            //    user = await App.MobileService.LoginAsync(v, provider);
            //}
            //catch (Exception ex)
            //{
            //}

            //return user; 
            return await App.MobileService.LoginAsync(view, provider);
        }
Example #31
0
 /// <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 Microsoft 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)
 {
     return(LoginAsync(client, provider, useSingleSignOn, parameters: null));
 }
Example #32
0
 /// <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 Microsoft 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>
 /// <param name="parameters">
 /// Provider specific extra parameters that are sent as query string parameters to login endpoint.
 /// </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, IDictionary <string, string> parameters)
 {
     return(LoginAsync(client, provider.ToString(), useSingleSignOn, parameters));
 }
 public Task LoginAsync(MobileServiceClient client, MobileServiceAuthenticationProvider provider)
 {
     return(client.LoginAsync(provider, null));
 }
 /// <summary>
 /// Log a user into a Mobile Services application given a provider name.
 /// </summary>
 /// <param name="client" type="Microsoft.WindowsAzure.MobileServices.IMobileServiceClient">
 /// The MobileServiceClient instance to login with
 /// </param>
 /// <param name="context" type="Android.Content.Context">
 /// The Context to display the Login UI in.
 /// </param>
 /// <param name="provider" type="MobileServiceAuthenticationProvider">
 /// Authentication provider to use.
 /// </param>
 /// <param name="parameters">
 /// Provider specific extra parameters that are sent as query string parameters to login endpoint.
 /// </param>
 /// <returns>
 /// Task that will complete when the user has finished authentication.
 /// </returns>
 public static Task <MobileServiceUser> LoginAsync(this IMobileServiceClient client, Context context, MobileServiceAuthenticationProvider provider, IDictionary <string, string> parameters)
 {
     return(LoginAsync(client, context, provider.ToString(), parameters));
 }
Example #35
0
        /// <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="token" type="JObject">
        /// Optional, provider specific object with existing OAuth token to log in with.
        /// </param>
        /// <returns>
        /// Task that will complete when the user has finished authentication.
        /// </returns>
        internal async Task <MobileServiceUser> SendLoginAsync(MobileServiceAuthenticationProvider provider, JObject token = null)
        {
            if (this.LoginInProgress)
            {
                throw new InvalidOperationException(Resources.MobileServiceClient_Login_In_Progress);
            }

            if (!Enum.IsDefined(typeof(MobileServiceAuthenticationProvider), provider))
            {
                throw new ArgumentOutOfRangeException("provider");
            }

            string providerName = provider.ToString().ToLower();

            this.LoginInProgress = true;
            try
            {
                JToken response = null;
                if (token != null)
                {
                    // Invoke the POST endpoint to exchange provider-specific token for a Windows Azure Mobile Services token

                    response = await this.RequestAsync("POST", LoginAsyncUriFragment + "/" + providerName, token);
                }
                else
                {
                    // Use PhoneWebAuthenticationBroker to launch server side OAuth flow using the GET endpoint

                    Uri startUri = new Uri(this.ApplicationUri, LoginAsyncUriFragment + "/" + providerName);
                    Uri endUri   = new Uri(this.ApplicationUri, LoginAsyncDoneUriFragment);

                    PhoneAuthenticationResponse result = await PhoneWebAuthenticationBroker.AuthenticateAsync(startUri, endUri);

                    if (result.ResponseStatus == PhoneAuthenticationStatus.ErrorHttp)
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.Authentication_Failed, result.ResponseErrorDetail));
                    }
                    else if (result.ResponseStatus == PhoneAuthenticationStatus.UserCancel)
                    {
                        throw new InvalidOperationException(Resources.Authentication_Canceled);
                    }

                    int i = result.ResponseData.IndexOf("#token=");
                    if (i > 0)
                    {
                        response = JToken.Parse(Uri.UnescapeDataString(result.ResponseData.Substring(i + 7)));
                    }
                    else
                    {
                        i = result.ResponseData.IndexOf("#error=");
                        if (i > 0)
                        {
                            throw new InvalidOperationException(string.Format(
                                                                    CultureInfo.InvariantCulture,
                                                                    Resources.MobileServiceClient_Login_Error_Response,
                                                                    Uri.UnescapeDataString(result.ResponseData.Substring(i + 7))));
                        }
                        else
                        {
                            throw new InvalidOperationException(Resources.MobileServiceClient_Login_Invalid_Response_Format);
                        }
                    }
                }

                // Get the Mobile Services auth token and user data
                this.currentUserAuthenticationToken = response.Get(LoginAsyncAuthenticationTokenKey).AsString();
                this.CurrentUser = new MobileServiceUser(response.Get("user").Get("userId").AsString());
            }
            finally
            {
                this.LoginInProgress = false;
            }

            return(this.CurrentUser);
        }
 /// <summary>
 /// Log a user into a Mobile Services application given a provider name.
 /// </summary>
 /// <param name="client" type="Microsoft.WindowsAzure.MobileServices.IMobileServiceClient">
 /// The MobileServiceClient instance to login with
 /// </param>
 /// <param name="context" type="Android.Content.Context">
 /// The Context to display the Login UI in.
 /// </param>
 /// <param name="provider" type="MobileServiceAuthenticationProvider">
 /// Authentication provider to use.
 /// </param>
 /// <returns>
 /// Task that will complete when the user has finished authentication.
 /// </returns>
 public static Task <MobileServiceUser> LoginAsync(this IMobileServiceClient client, Context context, MobileServiceAuthenticationProvider provider)
 {
     return(LoginAsync(client, context, provider, parameters: null));
 }
Example #37
0
 public Task LoginAsync(MobileServiceClient mobileServiceClient, MobileServiceAuthenticationProvider provider)
 {
     return(mobileServiceClient.LoginAsync(UIApplication.SharedApplication.KeyWindow.RootViewController, provider));
 }