public SettingsViewController (IntPtr handle) : base (handle)
		{
			_settingsService = ServiceLocator.Current.GetInstance<ISettingsService>();

			_auth0 = new Auth0Client (
				_settingsService.Auth0Domain,
				_settingsService.Auth0ClientId
			);
		}
			public override async void ViewDidAppear(bool animated)
			{
				base.ViewDidAppear(animated);
				if (_cancelledByUser || _justLoggedIn) return;
				Auth0Client auth0Client = null;
				//IdentityService identityService = null;
				if (_nativeView == null) return;
				var message = String.Empty;
				try
				{
					auth0Client = new Auth0Client(App.Instance.OAuthSettings.Domain, App.Instance.OAuthSettings.ClientId);//SimpleIoc.Default.GetInstance<Auth0Client>();
					//identityService = SimpleIoc.Default.GetInstance<IIdentityService>() as IdentityService;
					//if (identityService == null) return;
				 var user = await auth0Client.LoginAsync(ViewController, "servcorp.adfs.prod", true);


					_justLoggedIn = true;
				    

					//					if (eventArgs.IsAuthenticated) {
					//						// Use eventArgs.Account to do wonderful things
					App.Instance.SaveToken(user.Auth0AccessToken);

				    App.Instance.SuccessfulLoginAction.Invoke();
					//					} else {
					//						// The user cancelled
					//					}
				}
				catch (System.Threading.Tasks.TaskCanceledException cancelException)
				{
				App.Instance.FailureLoginAction.Invoke();
				//await App.Instance.NavigationPage.Navigation.PushModalAsync (new StartPage());
				MessagingCenter.Send<App> (App.Instance, "AuthenticationFailed");

					if (cancelException.Task != null &&
						cancelException.Task.Status == TaskStatus.Canceled)
						_cancelledByUser = true;
					message = cancelException.Message;
				App.Instance.ErrorMessage = message;
				App.Instance.NavigationPage.PopToRootAsync ().Wait();
				}
				catch (Exception exception)
				{
					message = exception.Message;
					//throw;
				}

				//if (identityService != null) identityService.SetIdentity(auth0Client, _cancelledByUser, message);
			}
Beispiel #3
0
        protected override void OnCreate (Bundle savedInstanceState)
        {
            _auth0 = new Auth0Client ("cryptocodes.auth0.com", "nYc5cfTehBlni7yCB4QpfgJQOu5876ce");
            base.OnCreate (savedInstanceState);

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

            _view = FindViewById<LinearLayout> (Resource.Id.mainView);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.loginButton);

            button.Click += delegate {
                ShowLogin ();
            };;
        }
//		public override void ViewDidLoad ()
//		{
//			
//		}
	
   protected override async void OnElementChanged (ElementChangedEventArgs<Page> e)
	{
			base.OnElementChanged(e);

			if (_cancelledByUser || _justLoggedIn) return;


			Auth0Client auth0Client = null;
			//IdentityService identityService = null;
			//if (_nativeView == null) return;
			var message = String.Empty;
			try
			{
				auth0Client = new Auth0Client(App.Instance.OAuthSettings.Domain, App.Instance.OAuthSettings.ClientId);//SimpleIoc.Default.GetInstance<Auth0Client>();
				//identityService = SimpleIoc.Default.GetInstance<IIdentityService>() as IdentityService;
				//if (identityService == null) return;
				var user = await auth0Client.LoginAsync(this.Context, "servcorp.adfs.prod", true);

				_justLoggedIn = true;
				App.Instance.SuccessfulLoginAction.Invoke();

				//					if (eventArgs.IsAuthenticated) {
				//						// Use eventArgs.Account to do wonderful things
				App.Instance.SaveToken(user.Auth0AccessToken);
				//					} else {
				//						// The user cancelled
				//					}
			}
			catch (System.Threading.Tasks.TaskCanceledException cancelException)
			{
				if (cancelException.Task != null &&
					cancelException.Task.Status == TaskStatus.Canceled)
					_cancelledByUser = true;
				message = cancelException.Message;
			}
			catch (Exception exception)
			{
				message = exception.Message;
				//throw;
			}
	}
 public AdfsAuthenticator(Auth0Client client)
 {
     _client = client;
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            this.NavigationItem.SetHidesBackButton (true, false);
            this.NavigationItem.SetLeftBarButtonItem(null, true);

            SetUILayOut ();

            // Code to start the Xamarin Test Cloud Agent
            #if ENABLE_TEST_CLOUD
            Xamarin.Calabash.Start ();
            #endif

            AppDelegate.IsFromSignUp = false;
            ButtonLogin.TouchUpInside +=  async (object sender, EventArgs e) => {

                loadingOverlay = new LoadingOverlay(this.View.Bounds);
                this.View.Add(loadingOverlay);

                if ( ValidateCredentials ()) {
                    // Call to Get user details and validate credentials
                    LandingTabBarVC landingVC = this.Storyboard.InstantiateViewController ("LandingTabBarVC") as LandingTabBarVC;
                    if (landingVC != null) {
                        this.NavigationController.PushViewController(landingVC, true);
                    }
                }
            };

            ButtonLinkedInLogin.TouchUpInside += async (object sender, EventArgs e) => {

                //var auth0 = new Auth0Client("donow.auth0.com","1ghdA3NFkpT9V7ibOuIKp8QK3oF49RId");
                var auth0 = new Auth0Client("donowx.auth0.com","T2GQGMUwY1jxHHD2sKTGtiX865rynYQh");
                Auth0User user = null;
                try
                {
                    user = await auth0.LoginAsync(this,"linkedin");

                }
                catch (AggregateException ex)
                {
                //this.SetResultText(e.Flatten().Message);
                }
                catch (Exception ex)
                {
                //this.SetResultText(e.Message);
                }

                if(user != null)
                {
                    loadingOverlay = new LoadingOverlay(this.View.Bounds);
                    this.View.Add(loadingOverlay);

                    AppDelegate.UserProfile = Newtonsoft.Json.JsonConvert.DeserializeObject<Profile>(user.Profile.ToString());

                    if(AppDelegate.UserProfile.email_verified == true)
                    {

                        //AppDelegate.UserDetails =  AppDelegate.userBL.GetUserFromEmail(AppDelegate.UserProfile.email);
                        AppDelegate.UserDetails =  AppDelegate.userBL.GetUserDetails(AppDelegate.UserProfile.email);

                        if(AppDelegate.UserDetails != null && AppDelegate.UserDetails.UserId > 0)
                        {

                            LandingTabBarVC landingVC = this.Storyboard.InstantiateViewController ("LandingTabBarVC") as LandingTabBarVC;
                            if (landingVC != null) {
                                this.NavigationController.PushViewController(landingVC, true);
                            }
                        }
                        else
                        {
                            signUpOtherDetailsVC signUpVC = this.Storyboard.InstantiateViewController ("signUpOtherDetailsVC") as signUpOtherDetailsVC;
                            if (signUpVC != null) {
            //								signUpVC.NavigationItem.SetHidesBackButton (true, false);
            //								signUpVC.NavigationItem.SetLeftBarButtonItem(null, true);

                                if (signUpVC != null) {
                                    signUpVC.NavigationItem.SetHidesBackButton (true, false);
                                }
                                this.NavigationController.PushViewController(signUpVC, true);
                            }
                        }
                    }
                }
            };

            ButtonSignUp.TouchUpInside += (object sender, EventArgs e) => {
                AppDelegate.UserProfile = null;
                signUpLoginDetailsVC signUpVC = this.Storyboard.InstantiateViewController ("signUpLoginDetailsVC") as signUpLoginDetailsVC;
                if (signUpVC != null) {
                    this.NavigationController.PushViewController(signUpVC, true);
                }
            };

            ButtonForgotPassword.TouchUpInside += (object sender, EventArgs e) => {

                ForgotPasswordVC forgotPasswordVC = this.Storyboard.InstantiateViewController ("ForgotPasswordVC") as ForgotPasswordVC;
                if (forgotPasswordVC != null) {
                    this.NavigationController.PushViewController(forgotPasswordVC, true);
                }
            };

            ButtonVideo.TouchUpInside += (object sender, EventArgs e) => {
                var url = new NSUrl ("http://www.youtube.com/watch?v=I0N-4Dtog6E");
                if (!UIApplication.SharedApplication.OpenUrl (url)) {
                    var av = new UIAlertView ("Error:",
                        "error in opening video link",
                        null,
                        "OK",
                        null);
                    av.Show ();
                };
            };

            ButtonWebsite.TouchUpInside += (object sender, EventArgs e) => {
                var url = new NSUrl ("http://donowx.com");
                if (!UIApplication.SharedApplication.OpenUrl (url)) {
                    var av = new UIAlertView ("Error:",
                        "error in opening video link",
                        null,
                        "OK",
                        null);
                    av.Show ();
                };
            };
        }