public void Login()
		{
			//base.UpdateLayout();

			if (!IsShown)
			{

				IsShown = true;

				// TODO: polymorfic
				Xamarin.Auth.Helpers.OAuth1 oauth1 = this.OAuth as Xamarin.Auth.Helpers.OAuth1;
				Xamarin.Auth.Helpers.OAuth2 oauth2 = this.OAuth as Xamarin.Auth.Helpers.OAuth2;

				if (null != oauth1)
				{
					Login(oauth1);
					return;
				}

				if (null != oauth2)
				{
					Login(oauth2);
					return;
				}

				throw new ArgumentOutOfRangeException("Unknown OAuth");
				/*

				*/
			}
			return;
		}
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            OAuth2Authenticator auth = new OAuth2Authenticator
                                       (
                clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                scope: oauth2.OAuth2_Scope,
                authorizeUrl: oauth2.OAuth_UriAuthorization,
                redirectUrl: oauth2.OAuth_UriCallbackAKARedirect
                                       );

            auth.AllowCancel = oauth2.AllowCancel;

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed         += Auth_Completed;
            auth.Error             += Auth_Error;
            auth.BrowsingCompleted += Auth_BrowsingCompleted;

            //Uri uri = auth.GetUI();
            Type page_type = auth.GetUI();

            //(System.Windows.Application.Current.RootVisual as PhoneApplicationFrame).Navigate(uri);
            this.Frame.Navigate(page_type, auth);

            return;
        }
Example #3
0
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            OAuth2Authenticator auth = new OAuth2Authenticator
                                       (
                clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                scope: oauth2.OAuth2_Scope,
                authorizeUrl: oauth2.OAuth_UriAuthorization,
                redirectUrl: oauth2.OAuth_UriCallbackAKARedirect
                                       );

            auth.AllowCancel = oauth2.AllowCancel;

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += Auth_Completed;

            UIViewController vc = auth.GetUI();

            UIView      sv1 = this.Superview;
            UITableView sv2 = (UITableView)sv1.Superview;
            UIWindow    sv3 = (UIWindow)sv2.Superview;

            sv3.RootViewController.PresentViewController(vc, true, null);

            return;
        }
        public void AuthenticateOAuth2(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            page = new PageOAuth
                   (
                oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                oauth2.OAuth2_Scope,
                oauth2.OAuth_UriAuthorization,
                oauth2.OAuth_UriCallbackAKARedirect,
                null,
                true
                   );

            Navigation.PushAsync(page);

            return;
        }
		private void Login(Xamarin.Auth.Helpers.OAuth2 oauth2)
		{
			global::Xamarin.Auth.OAuth2Authenticator auth = null;

			if (
				null == oauth2.OAuth1_UriAccessToken)
			{
				try
				{
					auth = 
						new global::Xamarin.Auth.OAuth2Authenticator 
						(
						clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
						scope: oauth2.OAuth2_Scope,
						authorizeUrl: oauth2.OAuth_UriAuthorization,
						redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
						getUsernameAsync: null
					);
				}
				catch (System.Exception exc)
				{
					throw exc;
				}
			}
			else
			{
				auth = 
					new global::Xamarin.Auth.OAuth2Authenticator 
						(
						clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, 
						clientSecret: oauth2.OAuth1_SecretKey_ConsumerSecret_APISecret,
						scope: oauth2.OAuth2_Scope,
						authorizeUrl: oauth2.OAuth_UriAuthorization,
						redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
						accessTokenUrl: oauth2.OAuth1_UriAccessToken,
						getUsernameAsync: null
						);

			}
			auth.Completed += Auth_Completed;

			//PresentViewController (auth.GetUI (), true, null);

			return;
		}
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            OAuth2Authenticator auth = null;

            if (oauth2.OAuth_UriAccessToken_UriRequestToken == null || string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret))
            {
                auth = new OAuth2Authenticator
                       (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect
                       );
            }
            else
            {
                auth = new OAuth2Authenticator
                       (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: "93e7f486b09bd1af4c38913cfaacbf8a384a50d2",
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken
                       );
            }

            auth.AllowCancel = oauth2.AllowCancel;

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed         += Auth_Completed;
            auth.Error             += Auth_Error;
            auth.BrowsingCompleted += Auth_BrowsingCompleted;

            //Uri uri = auth.GetUI();
            Type page_type = auth.GetUI();

            //(System.Windows.Application.Current.RootVisual as PhoneApplicationFrame).Navigate(uri);
            this.Frame.Navigate(page_type, auth);


            return;
        }
Example #7
0
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            OAuth2Authenticator auth = new OAuth2Authenticator
                                       (
                clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                scope: oauth2.OAuth2_Scope,
                authorizeUrl: oauth2.OAuth_UriAuthorization,
                redirectUrl: oauth2.OAuth_UriCallbackAKARedirect
                                       );

            auth.AllowCancel = oauth2.AllowCancel;

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed += Auth_Completed;

            var intent = auth.GetUI(this);

            StartActivity(intent);

            return;
        }
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            OAuth2Authenticator auth = null;

            if (oauth2.OAuth_UriAccessToken_UriRequestToken == null || string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret))
            {
                auth = new OAuth2Authenticator(
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect
                    );
            }
            else
            {
                auth = new OAuth2Authenticator(
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: "93e7f486b09bd1af4c38913cfaacbf8a384a50d2",
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken
                    );
            }

            auth.AllowCancel = oauth2.AllowCancel;

            // If authorization succeeds or is canceled, .Completed will be fired.
            auth.Completed         += Auth_Completed;
            auth.Error             += Auth_Error;
            auth.BrowsingCompleted += Auth_BrowsingCompleted;

            Uri uri = auth.GetUI();

            // For Xamarin.Forms refactoring
            Microsoft.Phone.Controls.PhoneApplicationPage this_page = this;
            this_page.NavigationService.Navigate(uri);

            return;
        }
        public void OnItemSelected(object sender, ItemTappedEventArgs args_tapped)
        {
            object item = args_tapped.Item;

            KeyValuePair <string, string> kvp = (KeyValuePair <string, string>)item;

            string provider = kvp.Value;

            switch (provider)
            {
            case "Facebook OAuth2":
                Xamarin.Auth.Helpers.OAuth2 oauth_facebook = null;
                oauth_facebook = Data.TestCases [provider] as Xamarin.Auth.Helpers.OAuth2;
                AuthenticateOAuth2(oauth_facebook);
                break;

            case "Twitter OAuth1":
                Xamarin.Auth.Helpers.OAuth1 oauth_twitter = null;
                oauth_twitter = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth1;
                AuthenticateOAuth1(oauth_twitter);
                break;

            case "Google OAuth2":
                Xamarin.Auth.Helpers.OAuth2 oauth_google = null;
                oauth_google = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth2;
                AuthenticateOAuth2(oauth_google);
                break;

            case "Microsoft Live OAuth2":
                Xamarin.Auth.Helpers.OAuth2 oauth_mslive = null;
                oauth_mslive = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth2;
                AuthenticateOAuth2(oauth_mslive);
                break;

            case "LinkedIn OAuth1":
                Xamarin.Auth.Helpers.OAuth1 oauth_linkedin1 = null;
                oauth_linkedin1 = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth1;
                AuthenticateOAuth1(oauth_linkedin1);
                break;

            case "LinkedIn OAuth2":
                Xamarin.Auth.Helpers.OAuth2 oauth_linkedin2 = null;
                oauth_linkedin2 = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth2;
                AuthenticateOAuth2(oauth_linkedin2);
                break;

            case "Github OAuth2":
                Xamarin.Auth.Helpers.OAuth2 oauth_github = null;
                oauth_github = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth2;
                AuthenticateOAuth2(oauth_github);
                break;

            case "Instagram OAuth2":
                Xamarin.Auth.Helpers.OAuth2 oauth_instagram = null;
                oauth_instagram = Data.TestCases[provider] as Xamarin.Auth.Helpers.OAuth2;
                AuthenticateOAuth2(oauth_instagram);
                break;

            default:
                DisplayAlert("Error", "Unknown OAuth Provider!", "OK");
                break;
            }
            ;

            this.Navigation.PushAsync(page);

            return;
        }
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            if
            (
                string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret)
            )
            {
                if (oauth2.OAuth_UriAccessToken_UriRequestToken == null)
                {
                    // Step 1.1 Creating and configuring an Authenticator
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui
                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                    //-------------------------------------------------------------
                }
                else if (oauth2.OAuth_UriAccessToken_UriRequestToken != null)
                {
                    // Step 1.1 Creating and configuring an Authenticator
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui
                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                    //-------------------------------------------------------------
                }
            }
            else
            {
                // Step 1.1 Creating and configuring an Authenticator
                Auth2 = new OAuth2Authenticator
                        (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                    // Native UI API switch
                    //      true    - NEW native UI support
                    //      false   - OLD embedded browser API [DEFAULT]
                    // DEFAULT will be switched to true in the near future 2017-04
                    isUsingNativeUI: test_native_ui
                        )
                {
                    ShowErrors  = false,
                    AllowCancel = oauth2.AllowCancel,
                };
            }

            // Step 1.2 Subscribing to Authenticator events
            // If authorization succeeds or is canceled, .Completed will be fired.
            Auth2.Completed         += Auth_Completed;
            Auth2.Error             += Auth_Error;
            Auth2.BrowsingCompleted += Auth_BrowsingCompleted;


            // Step 2.1 Creating Login UI
            UIKit.UIViewController ui_object = Auth2.GetUI();

            if (Auth2.IsUsingNativeUI == true)
            {
                // Step 2.2 Customizing the UI - Native UI [OPTIONAL]
                // In order to access SFSafariViewController API the cast is neccessary
                SafariServices.SFSafariViewController c = null;
                c = (SafariServices.SFSafariViewController)ui_object;
                //  add custom schema (App Linking) handling
                //    in AppDelegate.cs
                //         public override bool OpenUrl
                //                                (
                //                                    UIApplication application,
                //                                    NSUrl url,
                //                                    string sourceApplication,
                //                                    NSObject annotation
                //                                )
                //
                //  NOTE[s]
                //  *   custom scheme support only
                //      xamarinauth://localhost
                //      xamarin-auth://localhost
                //      xamarin.auth://localhost
                //  *   no http[s] scheme support

                // 2.2 Customizing the UI - Native UI [OPTIONAL]
                this.UICustomization(c);

                ui_object = c;
            }

            // Step 3 Present/Launch the Login UI
            PresentViewController(ui_object, true, null);


            return;
        }
Example #11
0
        public void OnItemSelected(object sender, ItemTappedEventArgs args_tapped)
        {
            object item = args_tapped.Item;

            KeyValuePair <string, string> kvp = (KeyValuePair <string, string>)item;

            string authentication_provider = kvp.Value;

            oauth1 = null;
            oauth2 = null;

            switch (authentication_provider)
            {
            case "Google OAuth2":
                SetPublicDemoDataGoogleOAuth2();
                SetSensitiveDataGoogleOAuth2();

                page = new PageLogin(oauth2);

                break;

            case "Facebook OAuth2":
                SetPublicDemoDataFacebookOAuth2();
                SetSensitiveDataFacebookOAuth2();

                page = new PageLogin(oauth2);

                break;

            case "Twitter OAuth1":
                SetPublicDemoDataTwitterOAuth1();
                SetSensitiveDataTwitterOAuth1();

                page = new PageLogin(oauth1);

                break;

            case "Microsoft Live OAuth2":
                SetPublicDemoDataMicrosoftLiveOAuth2();
                SetSensitiveDataMicrosoftLiveOAuth2();

                page = new PageLogin(oauth2);

                break;

            case "Instagram OAuth2":
                SetPublicDemoDataInstagramOAuth2();
                SetSensitiveDataInstagramOAuth2();

                page = new PageLogin(oauth2);

                break;

            case "LinkedIn OAuth1":
                SetPublicDemoDataLinkedInOAuth1();
                SetSensitiveDataLinkedInOAuth1();

                page = new PageLogin(oauth1);

                break;

            case "LinkedIn OAuth2":
                SetPublicDemoDataLinkedInOAuth2();
                SetSensitiveDataLinkedInOAuth2();

                page = new PageLogin(oauth2);

                break;

            case "Github OAuth2":
                SetPublicDemoDataGithubOAuth2();
                SetSensitiveDataGithubOAuth2();

                page = new PageLogin(oauth2);

                break;

            default:
                string msg = "Unknown Authentication Provider: " + authentication_provider;
                throw new NotImplementedException(msg);
            }

            this.Navigation.PushAsync(page);

            return;
        }
Example #12
0
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            if (oauth2.OAuth2_UriRequestToken == null || string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret))
            {
                //-------------------------------------------------------------
                // WalkThrough Step 1
                //      setting up Authenticator object
                Auth2 = new OAuth2Authenticator
                        (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    // Native UI API switch
                    //      true    - NEW native UI support
                    //      false   - OLD embedded browser API [DEFAULT]
                    // DEFAULT will be switched to true in the near future 2017-04
                    isUsingNativeUI: test_native_ui
                        )
                {
                    AllowCancel = oauth2.AllowCancel,
                };
                //-------------------------------------------------------------
            }
            else
            {
                //-------------------------------------------------------------
                // WalkThrough Step 1
                //      setting up Authenticator object
                Auth2 = new OAuth2Authenticator
                        (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: "93e7f486b09bd1af4c38913cfaacbf8a384a50d2",
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth2_UriRequestToken,
                    // Native UI API switch
                    //      true    - NEW native UI support
                    //      false   - OLD embedded browser API [DEFAULT]
                    // DEFAULT will be switched to true in the near future 2017-04
                    isUsingNativeUI: test_native_ui
                        )
                {
                    AllowCancel = oauth2.AllowCancel,
                };
                //-------------------------------------------------------------
            }


            // If authorization succeeds or is canceled, .Completed will be fired.
            Auth2.Completed         += Auth_Completed;
            Auth2.Error             += Auth_Error;
            Auth2.BrowsingCompleted += Auth_BrowsingCompleted;

            //#####################################################################
            // WalkThrough Step 2
            //      creating Presenter (UI) for specific platform
            // Xamarin.Auth API - Breaking Change
            //      old API returned global::Android.Content.Intent
            //Intent ui_intent_as_object = auth.GetUI ();
            //      new API returns System.Object
            Intent ui_object = Auth2.GetUI(this);

            if (Auth2.IsUsingNativeUI == true)
            {
                //=================================================================
                // WalkThrough Step 2.1
                //      casting UI object to proper type to work with
                //
                // Xamarin.Auth API - Native UI support
                //      *   Android - [Chrome] Custom Tabs on Android
                //          Android.Support.CustomTabs
                //          and
                //      *   iOS -  SFSafariViewController
                //          SafariServices.SFSafariViewController
                // on 2014-04-20 google (and some other providers) will work only with this API
                //
                //
                //  2017-03-25
                //      NEW UPCOMMING API undocumented work in progress
                //      soon to be default
                //      optional API in the future (for backward compatibility)
                //
                //  required part
                //  add
                //     following code:

                //------------------------------------------------------------
                //  add custom schema (App Linking) handling
                //      1.  add Activity with IntentFilter to the app
                //          1.1. Define sheme[s] and host[s] in the IntentFilter
                //          1.2. in Activity's OnCreate extract URL with custom schema from Intent
                //          1.3. parse OAuth data from URL obtained in 1.2.
                //  NOTE[s]
                //  *   custom scheme support only
                //      xamarinauth://localhost
                //      xamarin-auth://localhost
                //      xamarin.auth://localhost
                //  *   no http[s] scheme support
                //------------------------------------------------------------
            }

            //------------------------------------------------------------
            // WalkThrough Step 3
            //      Launching UI
            //      [REQUIRED]
            StartActivity(ui_object);
            //------------------------------------------------------------

            return;
        }
Example #13
0
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            if (string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret))
            {
                if (oauth2.OAuth_UriAccessToken_UriRequestToken == null)
                {
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui

                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                }
                else //if (oauth2.OAuth_UriAccessToken_UriRequestToken != null)
                {
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui

                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                }
            }
            else
            {
                Auth2 = new OAuth2Authenticator
                        (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                    // Native UI API switch
                    //      true    - NEW native UI support
                    //      false   - OLD embedded browser API [DEFAULT]
                    // DEFAULT will be switched to true in the near future 2017-04
                    isUsingNativeUI: test_native_ui

                        )
                {
                    ShowErrors  = false,
                    AllowCancel = oauth2.AllowCancel,
                };
                //-------------------------------------------------------------
            }


            // If authorization succeeds or is canceled, .Completed will be fired.
            Auth2.Completed         += Auth_Completed;
            Auth2.Error             += Auth_Error;
            Auth2.BrowsingCompleted += Auth_BrowsingCompleted;

            //#####################################################################
            // WalkThrough Step 2
            //      creating Presenter (UI) for specific platform
            // Xamarin.Auth API - Breaking Change
            //      old API returned global::Android.Content.Intent
            //Intent ui_intent_as_object = auth.GetUI ();
            //      new API returns System.Object
            Intent ui_object = Auth2.GetUI(this);

            //------------------------------------------------------------
            // WalkThrough Step 3
            //      Launching UI
            //      [REQUIRED]
            StartActivity(ui_object);

            return;
        }
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            if
            (
                string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret)
            )
            {
                if (oauth2.OAuth_UriAccessToken_UriRequestToken == null)
                {
                    //-------------------------------------------------------------
                    // WalkThrough Step 1
                    //      setting up Authenticator object
                    // Implicit
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui
                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                    //-------------------------------------------------------------
                }
                else if (oauth2.OAuth_UriAccessToken_UriRequestToken != null)
                {
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui
                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                    //-------------------------------------------------------------
                }
            }
            else
            {
                //-------------------------------------------------------------
                // WalkThrough Step 1
                //      setting up Authenticator object
                // Explicit
                Auth2 = new OAuth2Authenticator
                        (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                    // Native UI API switch
                    //      true    - NEW native UI support
                    //      false   - OLD embedded browser API [DEFAULT]
                    // DEFAULT will be switched to true in the near future 2017-04
                    isUsingNativeUI: test_native_ui
                        )
                {
                    ShowErrors  = false,
                    AllowCancel = oauth2.AllowCancel,
                };
                //-------------------------------------------------------------
            }


            // If authorization succeeds or is canceled, .Completed will be fired.
            Auth2.Completed         += Auth_Completed;
            Auth2.Error             += Auth_Error;
            Auth2.BrowsingCompleted += Auth_BrowsingCompleted;



            //=================================================================
            // WalkThrough Step 1.1
            //      Launching UI
            //      [REQUIRED]

            //  add custom schema (App Linking) handling
            //    in AppDelegate.cs
            //         public override bool OpenUrl
            //                                (
            //                                    UIApplication application,
            //                                    NSUrl url,
            //                                    string sourceApplication,
            //                                    NSObject annotation
            //                                )
            //
            //  NOTE[s]
            //  *   custom scheme support only
            //      xamarinauth://localhost
            //      xamarin-auth://localhost
            //      xamarin.auth://localhost
            //  *   no http[s] scheme support


            //#####################################################################
            // WalkThrough Step 2
            //      creating Presenter (UI) for specific platform
            // Xamarin.Auth API - Breaking Change
            //      old API returned UIKit.UIViewController
            // UIViewController ui_controller = auth.GetUI ();
            //      new API returns System.Object
            UIViewController ui_object = Auth2.GetUI();


            if (Auth2.IsUsingNativeUI == true)
            {
                //=================================================================
                // WalkThrough Step 2.1
                //      casting UI object to proper type to work with
                //
                // Xamarin.Auth API - Native UI support
                //      *   Android - [Chrome] Custom Tabs on Android
                //          Android.Support.CustomTabs
                //          and
                //      *   iOS -  SFSafariViewController
                //          SafariServices.SFSafariViewController
                // on 2014-04-20 google (and some other providers) will work only with this API
                //
                //
                //  2017-03-25
                //      NEW UPCOMMING API undocumented work in progress
                //      soon to be default
                //      optional API in the future (for backward compatibility)
                //
                //  required part
                //  add
                //     following code:

                SafariServices.SFSafariViewController c = null;
                c = (SafariServices.SFSafariViewController)ui_object;

                this.UICustomization(c);

                //------------------------------------------------------------
                ui_object = c;
            }

            PresentViewController(ui_object, true, null);
            //=================================================================
            //#####################################################################


            return;
        }
Example #15
0
        private void Authenticate(Xamarin.Auth.Helpers.OAuth2 oauth2)
        {
            if (string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret))
            {
                if (oauth2.OAuth_UriAccessToken_UriRequestToken == null)
                {
                    // Step 1.1 Creating and configuring an Authenticator
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui

                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                }
                else //if (oauth2.OAuth_UriAccessToken_UriRequestToken != null)
                {
                    // Step 1.1 Creating and configuring an Authenticator
                    Auth2 = new OAuth2Authenticator
                            (
                        clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                        clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                        scope: oauth2.OAuth2_Scope,
                        authorizeUrl: oauth2.OAuth_UriAuthorization,
                        redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                        accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                        // Native UI API switch
                        //      true    - NEW native UI support
                        //      false   - OLD embedded browser API [DEFAULT]
                        // DEFAULT will be switched to true in the near future 2017-04
                        isUsingNativeUI: test_native_ui

                            )
                    {
                        ShowErrors  = false,
                        AllowCancel = oauth2.AllowCancel,
                    };
                }
            }
            else
            {
                // Step 1.1 Creating and configuring an Authenticator
                Auth2 = new OAuth2Authenticator
                        (
                    clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                    clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                    scope: oauth2.OAuth2_Scope,
                    authorizeUrl: oauth2.OAuth_UriAuthorization,
                    redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                    accessTokenUrl: oauth2.OAuth_UriAccessToken_UriRequestToken,
                    // Native UI API switch
                    //      true    - NEW native UI support
                    //      false   - OLD embedded browser API [DEFAULT]
                    // DEFAULT will be switched to true in the near future 2017-04
                    isUsingNativeUI: test_native_ui

                        )
                {
                    ShowErrors  = false,
                    AllowCancel = oauth2.AllowCancel,
                };
            }


            // Step 1.2 Subscribing to Authenticator events
            // If authorization succeeds or is canceled, .Completed will be fired.
            Auth2.Completed         += Auth_Completed;
            Auth2.Error             += Auth_Error;
            Auth2.BrowsingCompleted += Auth_BrowsingCompleted;

            // Step 2.1 Creating Login UI
            global::Android.Content.Intent ui_object = Auth2.GetUI(this);

            if (Auth2.IsUsingNativeUI == true)
            {
                // Step 2.2 Customizing the UI - Native UI [OPTIONAL]
                // In order to access CustomTabs API
                Xamarin.Auth.CustomTabsConfiguration.AreAnimationsUsed          = true;
                Xamarin.Auth.CustomTabsConfiguration.IsShowTitleUsed            = false;
                Xamarin.Auth.CustomTabsConfiguration.IsUrlBarHidingUsed         = false;
                Xamarin.Auth.CustomTabsConfiguration.IsCloseButtonIconUsed      = false;
                Xamarin.Auth.CustomTabsConfiguration.IsActionButtonUsed         = false;
                Xamarin.Auth.CustomTabsConfiguration.IsActionBarToolbarIconUsed = false;
                Xamarin.Auth.CustomTabsConfiguration.IsDefaultShareMenuItemUsed = false;
                Xamarin.Auth.CustomTabsConfiguration.MenuItemTitle = null;
                Xamarin.Auth.CustomTabsConfiguration.ToolbarColor  = global::Android.Graphics.Color.Orange;
            }

            // Step 3 Present/Launch the Login UI
            StartActivity(ui_object);

            return;
        }