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


C# MobileServiceAuthenticationProvider.ToString方法代码示例

本文整理汇总了C#中MobileServiceAuthenticationProvider.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MobileServiceAuthenticationProvider.ToString方法的具体用法?C# MobileServiceAuthenticationProvider.ToString怎么用?C# MobileServiceAuthenticationProvider.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MobileServiceAuthenticationProvider的用法示例。


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

示例1: 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);
            }
        }
开发者ID:Microsoft,项目名称:Appsample-Photosharing,代码行数:36,代码来源:AuthenticationHandler.cs

示例2: AuthenticateAsync

		public async Task AuthenticateAsync(MobileServiceAuthenticationProvider provider)
		{
			var passwordVault = new PasswordVault();
			PasswordCredential credential = null;

			var settings = ApplicationData.Current.RoamingSettings;

			try
			{
				await this.MobileService.LoginAsync(provider);
				credential = new PasswordCredential(provider.ToString(), this.MobileService.User.UserId, this.MobileService.User.MobileServiceAuthenticationToken);
				passwordVault.Add(credential);

				settings.Values[LastUsedProvider] = provider.ToString();

				this.OnNavigate?.Invoke(Tasks, null);
			}
			catch (InvalidOperationException)
			{
				await this.OnShowErrorAsync?.Invoke("Authentication failed. Please try again.");
			}
        }
开发者ID:brentedwards,项目名称:MobileTasks,代码行数:22,代码来源:LoginViewModel.cs

示例3: TestLoginAsync

        /// <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);
        }
开发者ID:KevinOrtman,项目名称:azure-mobile-services,代码行数:23,代码来源:LoginTests.cs

示例4: TestLoginAsync

        /// <summary>
        /// Tests the <see cref="MobileServiceClient.LoginAsync"/> functionality on the platform.
        /// </summary>
        /// <param name="provider">The provider with which to login.
        /// </param>
        /// <param name="useSingleSignOn">Indicates if single sign-on should be used when logging in.
        /// </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 useSingleSignOn, bool useProviderStringOverload)
        {
            MobileServiceUser user;
            await TestCRUDAsync("Public", false, false);
            await TestCRUDAsync("Authorized", true, false);
            if (useProviderStringOverload)
            {
                user = await client.LoginAsync(provider.ToString(), useSingleSignOn);
            }
            else
            {
                user = await client.LoginAsync(provider, useSingleSignOn);
            }
            await TestCRUDAsync("Public", false, true);
            await TestCRUDAsync("Authorized", true, true);
            await TestLogoutAsync();
            await TestCRUDAsync("Authorized", true, false);

            return string.Format("UserId: {0} Token: {1}", user.UserId, user.MobileServiceAuthenticationToken);
        }
开发者ID:gb92,项目名称:azure-mobile-apps-net-client,代码行数:31,代码来源:LoginTests.cs

示例5: Authenticate

        public async Task Authenticate(MobileServiceAuthenticationProvider provider)
        {
            while (App.MobileServicesUser == null)
            {
                string message = null;
                try
                {
                    App.MobileServicesUser = await App.MobileService.LoginAsync(provider);

                    App.RegisterWithMobileServices(provider.ToString());
                    NavigationService.Navigate(new Uri("/ChatPage.xaml", UriKind.Relative));
                }
                catch (InvalidOperationException ex)
                {
                    ex.ToString();
                    message = "You must log in. Login Required";
                }
                if (message != null)
                {
                    MessageBox.Show(message);
                }
            }
        }
开发者ID:babilavena,项目名称:Chat-App,代码行数:23,代码来源:LoginPage.xaml.cs

示例6: Authenticate

 private async Task Authenticate(MobileServiceAuthenticationProvider provider)
 {
     while (App.MobileServicesUser == null)
     {
         string message = null;
         try
         {
             App.MobileServicesUser = await App.MobileService.LoginAsync(provider);
             App.RegisterWithMobileServices(provider.ToString());
             this.Frame.Navigate(typeof(ChatPage));
         }
         catch (InvalidOperationException ex)
         {
             ex.ToString();
             message = "You must log in. LoginPage Required";
         }
         if (message != null)
         {
             var dialog = new MessageDialog(message);
             dialog.Commands.Add(new UICommand("OK"));
             await dialog.ShowAsync();
         }
     }
 }
开发者ID:babilavena,项目名称:Chat-App,代码行数:24,代码来源:LoginPage.xaml.cs

示例7: LoginAsync

 /// <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="viewController" type="MonoTouch.UIKit.UIViewController">
 /// UIViewController used to display modal login UI on iPhone/iPods.
 /// </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, UIViewController viewController, MobileServiceAuthenticationProvider provider, IDictionary<string, string> parameters)
 {
     return LoginAsync(client, default(RectangleF), viewController, provider.ToString(), parameters);
 }
开发者ID:brettsam,项目名称:azure-mobile-apps-net-client,代码行数:22,代码来源:MobileServiceClientExtensions.cs

示例8: SendLoginAsync

        /// <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="JsonObject">
        /// 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, JsonObject 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
            {
                IJsonValue 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 WebAuthenicationBroker 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);

                    WebAuthenticationResult result = await WebAuthenticationBroker.AuthenticateAsync(
                        WebAuthenticationOptions.None, startUri, endUri);

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

                    int i = result.ResponseData.IndexOf("#token=");
                    if (i > 0)
                    {
                        response = JsonValue.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;
        }
开发者ID:subbuballa,项目名称:azure-mobile-services,代码行数:88,代码来源:MobileServiceClient.cs

示例9: LoginAsync

 /// <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="rectangle" type="System.Drawing.RectangleF">
 /// The area in <paramref name="view"/> to anchor to.
 /// </param>
 /// <param name="view" type="MonoTouch.UIKit.UIView">
 /// UIView used to display a popover from on iPad.
 /// </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, RectangleF rectangle, UIView view, MobileServiceAuthenticationProvider provider)
 {
     return LoginAsync(client, rectangle, (object)view, provider.ToString());
 }
开发者ID:neilboyd,项目名称:azure-mobile-services,代码行数:22,代码来源:MobileServiceClientExtensions.cs

示例10: LoginAsync

        public async Task<MobileServiceUser> LoginAsync(MobileServiceAuthenticationProvider provider)
        {
            IDictionary<string, string> p = new Dictionary<string, string>();

            return await ContosoMoments.App.MobileService.LoginAsync(provider.ToString(), p);
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:6,代码来源:MobileClient.cs

示例11: 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 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.ToString(), useSingleSignOn);
 }
开发者ID:neilboyd,项目名称:azure-mobile-services,代码行数:22,代码来源:SingleSignOnExtensions.cs

示例12: SendLoginAsync

        internal Task<MobileServiceUser> SendLoginAsync(RectangleF rect, object view, MobileServiceAuthenticationProvider provider, JsonObject 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;

            TaskCompletionSource<MobileServiceUser> tcs = new TaskCompletionSource<MobileServiceUser> ();

            if (token != null)
            {
                // Invoke the POST endpoint to exchange provider-specific token for a Windows Azure Mobile Services token

                this.RequestAsync("POST", LoginAsyncUriFragment + "/" + providerName, token)
                    .ContinueWith (t =>
                    {
                        this.LoginInProgress = false;

                        if (t.IsCanceled)
                            tcs.SetCanceled();
                        else if (t.IsFaulted)
                            tcs.SetException (t.Exception.InnerExceptions);
                        else
                        {
                            SetupCurrentUser (t.Result);
                            tcs.SetResult (this.CurrentUser);
                        }
                    });
            }
            else
            {
                // Launch server side OAuth flow using the GET endpoint

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

                WebRedirectAuthenticator auth = new WebRedirectAuthenticator (startUri, endUri);
                auth.ClearCookiesBeforeLogin = false;

                UIViewController c = auth.GetUI();

                UIViewController controller = null;
                UIPopoverController popover = null;

                auth.Error += (o, e) =>
                {
                    this.LoginInProgress = false;

                    if (controller != null)
                        controller.DismissModalViewControllerAnimated (true);
                    if (popover != null)
                        popover.Dismiss (true);

                    Exception ex = e.Exception ?? new Exception (e.Message);
                    tcs.TrySetException (ex);
                };
                
                auth.Completed += (o, e) =>
                {
                    this.LoginInProgress = false;

                    if (controller != null)
                        controller.DismissModalViewControllerAnimated (true);
                    if (popover != null)
                        popover.Dismiss (true);

                    if (!e.IsAuthenticated)
                        tcs.TrySetCanceled();
                    else
                    {
                        SetupCurrentUser (JsonValue.Parse (e.Account.Properties["token"]));
                        tcs.TrySetResult (this.CurrentUser);
                    }
                };

                controller = view as UIViewController;
                if (controller != null)
                {
                    controller.PresentModalViewController (c, true);
                }
                else
                {
                    UIView v = view as UIView;
                    UIBarButtonItem barButton = view as UIBarButtonItem;

                    popover = new UIPopoverController (c);

                    if (barButton != null)
                        popover.PresentFromBarButtonItem (barButton, UIPopoverArrowDirection.Any, true);
                    else
                        popover.PresentFromRect (rect, v, UIPopoverArrowDirection.Any, true);
//.........这里部分代码省略.........
开发者ID:xamarin,项目名称:azure-mobile-services,代码行数:101,代码来源:MobileServiceClient.iOS.cs

示例13: Login

 private async void Login(MobileServiceAuthenticationProvider provider)
 {
     var client = new MobileServiceClient(this.uriEntry.Value);
     var user = await client.LoginAsync(this, provider);
     var alert = new UIAlertView("Welcome", provider.ToString() + " Login succeeded. Your userId is: " + user.UserId, null, "OK");
     alert.Show();
 }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:7,代码来源:LoginViewController.cs

示例14: LoginAsync

 /// <summary>
 /// Log a user into a Mobile Services application given a provider name.
 /// </summary>
 /// <param name="client">
 /// The client.
 /// </param>
 /// <param name="provider">
 /// 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, MobileServiceAuthenticationProvider provider, IDictionary<string, string> parameters)
 {
     return LoginAsync(client, provider.ToString(), parameters);
 }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:19,代码来源:MobileServiceClientExtensions.cs

示例15: LoginAsync

 /// <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.ToString());            
 }
开发者ID:rfaisal,项目名称:azure-mobile-services,代码行数:19,代码来源:MobileServiceClientExtensions.cs


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