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


C# OAuth2Authenticator.GetUI方法代码示例

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


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

示例1: OnElementChanged

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);
            var activity = Context as Activity;

            var auth = new OAuth2Authenticator(
                clientId: "actioncenterapp", // your OAuth2 client id
                scope: "actioncenter", // the scopes for the particular API you're accessing, delimited by "+" symbols
                authorizeUrl: new Uri("https://idsat.nwpsmart.com/identity/connect/authorize"), // the auth URL for the service
                redirectUrl: new Uri("https://actioncenterapp/callback/")); // the redirect URL for the service

            auth.Completed += (sender, eventArgs) =>
            {
                if (eventArgs.IsAuthenticated)
                {
                    // Use eventArgs.Account to do wonderful things
                    App.SaveToken(eventArgs.Account.Properties["access_token"]);
                    //PushClient.Register(Context, "730398132449");
                    //var id = PushClient.GetRegistrationId(Context);
                    //App.SaveRegistrationId(id);
                    var page = Element as LoginPage;
                    if (page != null) page.NavigateToHome();
                }
                else
                {
                    // The user cancelled
                }
            };
            if (activity != null) activity.StartActivity(auth.GetUI(activity));
        }
开发者ID:dahlsailrunner,项目名称:ActionCenter,代码行数:30,代码来源:LoginPageRenderer.cs

示例2: ViewDidAppear

		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			// Retrieve any stored account information
			var accounts = AccountStore.Create ().FindAccountsForService (App.AppName);
			var account = accounts.FirstOrDefault ();

			if (account == null) {
				if (!isShown) {
					isShown = true;

					// Initialize the object that communicates with the OAuth service
					var auth = new OAuth2Authenticator (
						           Constants.ClientId,
						           Constants.ClientSecret,
						           Constants.Scope,
						           new Uri (Constants.AuthorizeUrl),
						           new Uri (Constants.RedirectUrl),
						           new Uri (Constants.AccessTokenUrl));

					// Register an event handler for when the authentication process completes
					auth.Completed += OnAuthenticationCompleted;

					// Display the UI
					PresentViewController (auth.GetUI (), true, null);
				}
			} else {
				if (!isShown) {
					App.User.Email = account.Username;
					App.SuccessfulLoginAction.Invoke ();					
				}
			}
		}
开发者ID:kevincwq,项目名称:XamarinLearn,代码行数:34,代码来源:AuthenticationPageRenderer.cs

示例3: LoginPageRenderer

		public LoginPageRenderer()
		{
			var activity = this.Context as Activity;

			var auth = new OAuth2Authenticator (
				clientId: "1500267916942625", // your OAuth2 client id
				scope: "", // the scopes for the particular API you're accessing, delimited by "+" symbols
				authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
				redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

			auth.Completed += async (sender, eventArgs) => {
				if (eventArgs.IsAuthenticated) {
					var accessToken = eventArgs.Account.Properties ["access_token"].ToString ();
					var expiresIn = Convert.ToDouble (eventArgs.Account.Properties ["expires_in"]);
					var expiryDate = DateTime.Now + TimeSpan.FromSeconds (expiresIn);

					var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, eventArgs.Account);
					var response = await request.GetResponseAsync ();
					var obj = JObject.Parse (response.GetResponseText ());

					var id = obj ["id"].ToString ().Replace ("\"", ""); 
					var name = obj ["name"].ToString ().Replace ("\"", "");

					App.NavigateToProfile(string.Format("Olá {0}", name));
				} else {
					App.NavigateToProfile("Usuário Cancelou o login");
				}
			};

			activity.StartActivity (auth.GetUI(activity));	
		}
开发者ID:angelobelchior,项目名称:xamarin.forms.facebooklogin,代码行数:31,代码来源:LoginPageRenderer.cs

示例4: OnElementChanged

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            // this is a ViewGroup - so should be able to load an AXML file and FindView<>
            var activity = Context as Activity;

            var auth = new OAuth2Authenticator(Constants.FacebookClientId, // your OAuth2 client id
                Constants.FaceBookScope,
                // The scopes for the particular API you're accessing. The format for this will vary by API.
                new Uri(Constants.FacebookAuthUrl), // the auth URL for the service
                new Uri(Constants.FacebookRedirect)); // the redirect URL for the service

            auth.Completed += (sender, eventArgs) =>
            {
                App.Instance.SuccessfulLoginAction(eventArgs.Account.Properties["access_token"]);
                if (eventArgs.IsAuthenticated)
                {
                    //App.Instance.SuccessfulLoginAction(eventArgs.Account.Properties["access_token"]);
                    // Use eventArgs.Account to do wonderful things
                    //App.Instance.SaveToken(eventArgs.Account.Properties["access_token"]);
                }
            };

            activity.StartActivity(auth.GetUI(activity));
        }
开发者ID:travo12,项目名称:GameCode,代码行数:26,代码来源:LoginPageRenderer.cs

示例5: OnElementChanged

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged (e);

            // this is a ViewGroup - so should be able to load an AXML file and FindView<>
            var activity = this.Context as Activity;

            var auth = new OAuth2Authenticator (
                clientId: "pXQhRdqeGPraG8z85f139g", // your OAuth2 client id
                scope: "", // The scopes for the particular API you're accessing. The format for this will vary by API.
                authorizeUrl: new Uri ("https://www.yammer.com/dialog/oauth"), // the auth URL for the service
                redirectUrl: new Uri ("http://deamon.info/university/330/yammer.php")); // the redirect URL for the service

            auth.Completed += (sender, eventArgs) => {
                //Console.WriteLine("hi");
                //Console.WriteLine(eventArgs);
                if (eventArgs.IsAuthenticated) {
                    App.SuccessfulLoginAction.Invoke();
                    Console.WriteLine("yammer connected");
                    Console.WriteLine(eventArgs.Account);
                    // Use eventArgs.Account to do wonderful things
                    App.SaveToken(eventArgs.Account.Properties["access_token"]);
                } else {
                    // The user cancelled
                    Console.WriteLine("yammer not connected");
                }
                //Console.WriteLine("bye");
                //Console.WriteLine(App.Token);
            };

            activity.StartActivity (auth.GetUI(activity));
        }
开发者ID:dittopower,项目名称:330-App---Tconnect,代码行数:32,代码来源:LoginPageRenderer.cs

示例6: LoginToFacebook

		void LoginToFacebook (object sender, EventArgs e)
		{
			var auth = new OAuth2Authenticator (
				clientId: "346691492084618",
				scope: "",
				authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
				redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

			// If authorization succeeds or is canceled, .Completed will be fired.
			auth.Completed += (s, ee) => {
				if (!ee.IsAuthenticated) {
					this.facebookStatus.Text = "Not Authenticated";
					return;
				}

				// Now that we're logged in, make a OAuth2 request to get the user's info.
				var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, ee.Account);
				request.GetResponseAsync().ContinueWith (t => {
					if (t.IsFaulted)
						this.facebookStatus.Text = "Error: " + t.Exception.InnerException.Message;
					else if (t.IsCanceled)
						this.facebookStatus.Text = "Canceled";
					else
					{
						var obj = JsonValue.Parse (t.Result.GetResponseText());
						this.facebookStatus.Text = "Logged in as " + obj["name"];
					}
				}, uiScheduler);
			};

			var intent = auth.GetUI (this);
			StartActivityForResult (intent, 42);
		}
开发者ID:pjcollins,项目名称:Xamarin.Auth,代码行数:33,代码来源:MainActivity.cs

示例7: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            var auth = new OAuth2Authenticator (
                clientId: "1647251678863645",
                scope: "",
                authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
                redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

            auth.Completed += (sender, eventArgs) => {

                if (eventArgs.IsAuthenticated) {
                    // Use eventArgs.Account to do wonderful things
                    StartActivity (typeof(DashActivity));

                } else {
                    // The user cancelled
                    StartActivity (typeof(MainActivity));
                }
            };

            StartActivity (auth.GetUI (this));
        }
开发者ID:sudo-wrestlers,项目名称:hackathon,代码行数:27,代码来源:LoginActivity.cs

示例8: OnElementChanged

        // protected override void OnModelChanged (VisualElement oldModel, VisualElement newModel)
        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged (e);
            var activity = this.Context as Activity;

            var auth = new OAuth2Authenticator (
                clientId: App.Current.Properties ["clientId"].ToString(),
                scope: App.Current.Properties ["scope"].ToString(),
                authorizeUrl: new Uri( App.Current.Properties ["authorizeUrl"].ToString()),
                redirectUrl: new Uri(App.Current.Properties ["redirectUrl"].ToString())

            );

            auth.Completed += (sender,eventArgs) => {
                if (eventArgs.IsAuthenticated){

                    App.Current.Properties ["access_token"] = eventArgs.Account.Properties ["access_token"].ToString();
                    if(App.Current.Properties ["access_token"].ToString().Length>0)
                    {
                       //use the eventargs to do good stuff
                       AccountStore.Create (activity).Save (eventArgs.Account, "Google");
                       App.Current.MainPage = new ProfilePage();
                    }
                }
                else
                {
                    //User Cancelled
                }
            };

            activity.StartActivity(auth.GetUI(activity));
        }
开发者ID:Jake-a-Lake,项目名称:GaragePrincess,代码行数:33,代码来源:LoginPageRenderer.cs

示例9: SignInAsync

		public async Task SignInAsync (string clientId, Uri authUrl, Uri callbackUrl, Action<string> tokenCallback, Action<string> errorCallback)
		{
			var auth = new OAuth2Authenticator (clientId, string.Empty, authUrl, callbackUrl);
			auth.AllowCancel = true;

			var controller = auth.GetUI ();
			await UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewControllerAsync (controller, true);

			auth.Completed += (s, e) => {
				controller.DismissViewController (true, null);
				if(e.Account != null && e.IsAuthenticated)
				{
					if(tokenCallback != null)
						tokenCallback(e.Account.Properties["access_token"]);
				}
				else
				{
					if(errorCallback != null)
						errorCallback("Not authenticated");
				}
			};

			auth.Error += (s, e) => {
				controller.DismissViewController (true, null);
				if(errorCallback != null)
					errorCallback(e.Message);
			};
		}
开发者ID:blombas,项目名称:TripLog,代码行数:28,代码来源:AuthService.cs

示例10: ViewDidAppear

		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			// url : http://stackoverflow.com/questions/24105390/how-to-login-to-facebook-in-xamarin-forms
			if(	visible == false )
			{
				visible = true;

				var auth = new OAuth2Authenticator (
					clientId: App.OAuthSettings.ClientId, // your OAuth2 client id
					scope: App.OAuthSettings.Scope, // The scopes for the particular API you're accessing. The format for this will vary by API.
					authorizeUrl: new Uri (App.OAuthSettings.AuthorizeUrl), // the auth URL for the service
					redirectUrl: new Uri (App.OAuthSettings.RedirectUrl)); // the redirect URL for the service

				auth.Completed += (sender, eventArgs) => {
					App.SuccessfulLoginAction.Invoke();

					if (eventArgs.IsAuthenticated)
					{
						App.SaveToken(eventArgs.Account.Properties["access_token"]);
					} 
					else 
					{
						// The user cancelled
					}
				};

				PresentViewController (auth.GetUI (), true, null);
			}
		}
开发者ID:adrianstevens,项目名称:Xamarin.Auth,代码行数:31,代码来源:LoginPageRenderer.cs

示例11: FacebookPageRenderer

        public FacebookPageRenderer()
        {
            var activity = this.Context as Activity;
            var auth = new OAuth2Authenticator(
            clientId: "476292725915235",
            scope: "",
            authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
            redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"));

            auth.Completed += async (sender, eventArgs) => {
                if (eventArgs.IsAuthenticated)
                {
                    var accessToken = eventArgs.Account.Properties["access_token"].ToString();
                    var expiresIn = Convert.ToDouble(eventArgs.Account.Properties["expires_in"]);
                    var expiryDate = DateTime.Now + TimeSpan.FromSeconds(expiresIn);

                    var request = new OAuth2Request("GET", new Uri("https://graph.facebook.com/me"), null, eventArgs.Account);
                    var response = await request.GetResponseAsync();
                    var obj = JObject.Parse(response.GetResponseText());

                    var id = obj["id"].ToString().Replace("\"", "");
                    var name = obj["name"].ToString().Replace("\"", "");

                    App app = new App();
                   await app.NavigateToProfile(string.Format("Olá {0}", name));

                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Alerta", "lOGIN CANCELADO", " OK");

                }
            };
            activity.StartActivity(auth.GetUI(activity));
        }
开发者ID:bruno-wladimir,项目名称:Faculdade,代码行数:35,代码来源:FacebookPageRenderer.cs

示例12: OnElementChanged

		protected override void OnElementChanged (ElementChangedEventArgs<Page> e)
		{
			base.OnElementChanged (e);

			// Retrieve any stored account information
			var accounts = AccountStore.Create (Context).FindAccountsForService (App.AppName);
			var account = accounts.FirstOrDefault ();

			if (account == null) {
				if (!isShown) {
					isShown = true;

					// Initialize the object that communicates with the OAuth service
					var auth = new OAuth2Authenticator (
						           Constants.ClientId,
						           Constants.ClientSecret,
						           Constants.Scope,
						           new Uri (Constants.AuthorizeUrl),
						           new Uri (Constants.RedirectUrl),
						           new Uri (Constants.AccessTokenUrl));

					// Register an event handler for when the authentication process completes
					auth.Completed += OnAuthenticationCompleted;

					// Display the UI
					var activity = Context as Activity;
					activity.StartActivity (auth.GetUI (activity));
				}
			} else {
				if (!isShown) {
					App.User.Email = account.Username;
					App.SuccessfulLoginAction.Invoke ();
				}
			}
		}
开发者ID:kevincwq,项目名称:XamarinLearn,代码行数:35,代码来源:AuthenticationPageRenderer.cs

示例13: ViewDidAppear

		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidAppear (animated);

			var auth = new OAuth2Authenticator (
				clientId: App.Instance.OAuthSettings.ClientId, // your OAuth2 client id
				scope: App.Instance.OAuthSettings.Scope, // The scopes for the particular API you're accessing. The format for this will vary by API.
				authorizeUrl: new Uri (App.Instance.OAuthSettings.AuthorizeUrl), // the auth URL for the service
				redirectUrl: new Uri (App.Instance.OAuthSettings.RedirectUrl)); // the redirect URL for the service

				
				

			auth.Completed += (sender, eventArgs) => {
				// We presented the UI, so it's up to us to dimiss it on iOS.
				App.Instance.SuccessfulLoginAction.Invoke();

				if (eventArgs.IsAuthenticated) {
					// Use eventArgs.Account to do wonderful things
					App.Instance.SaveToken(eventArgs.Account.Properties["access_token"]);
				} else {
					// The user cancelled
				}
			};

			PresentViewController (auth.GetUI (), true, null);
		}
开发者ID:Gunner92,项目名称:OAuthTwoDemo.XForms,代码行数:27,代码来源:LoginPageRenderer.cs

示例14: OnElementChanged

        protected override void OnElementChanged(ElementChangedEventArgs<Page> e)
        {
            base.OnElementChanged(e);

            var activity = Context as Activity;

            var auth = new OAuth2Authenticator(
                clientId: "actioncenterapp", // OAuth2 client id
                scope: "actioncenter", // the scopes for the particular API you're accessing, delimited by "+" symbols
                authorizeUrl: new Uri("https://idsat.nwpsmart.com/identity/connect/authorize"), // the auth URL for the service
                redirectUrl: new Uri("https://actioncenterapp/callback/")); // the redirect URL for the service

            auth.Completed += (sender, eventArgs) =>
            {
                if (eventArgs.IsAuthenticated)
                {
                    App.SaveToken(eventArgs.Account.Properties["access_token"]);
                    var page = Element as LoginPage;
                    page?.NavigateToHome();
                }
                else
                {
                    // The user cancelled
                }
            };

            activity.StartActivity(auth.GetUI(activity));
        }
开发者ID:dahlsailrunner,项目名称:AuthSample,代码行数:28,代码来源:LoginPageRenderer.cs

示例15: ViewDidAppear

        public override void ViewDidAppear(bool animated)
        {
            if (!IsShown)
            {
                IsShown = true;
                base.ViewDidAppear(animated);

                var auth = new OAuth2Authenticator(
                               clientId: "YOUR_OAUTH2_CLIENT_ID",
                               scope: "WHAT_ARE_YOU_ACCESSING_DELIMITED_+_SYMBOLS",
                               authorizeUrl: new Uri("AUTH_URL_FOR_SERVICE"),
                               redirectUrl: new Uri("REDIRECT_URL_FOR_THE_SERVICE")
                           );
                auth.Completed += (sender, eventArgs) =>
                {
                    App.SuccessfulLoginAction.Invoke();
                    if (eventArgs.IsAuthenticated)
                        App.SaveFacebookToken(eventArgs.Account.Properties["access_token"]);
                    else
                    {
                        // cancelled
                    }
                };

                PresentViewController(auth.GetUI(), true, null);
            }
        }
开发者ID:nodoid,项目名称:xamauth,代码行数:27,代码来源:LoginPageRenderer.cs


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