protected void ProviderSamplesList_Handle_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
        {
            Type   selection_type = e.SelectedItem.GetType();
            string selection      = selection_type.ToString().Replace("Xamarin.Auth.ProviderSamples.", "");

            System.Diagnostics.Debug.WriteLine($"    Provider Sample");
            System.Diagnostics.Debug.WriteLine($"        Selection = {selection}");

            Xamarin.Auth.WebAuthenticator authenticator = null;

            Xamarin.Auth.ProviderSamples.Helpers.OAuth1 oauth1 = null;
            Xamarin.Auth.ProviderSamples.Helpers.OAuth2 oauth2 = null;

            oauth2 = Activator.CreateInstance(selection_type) as Xamarin.Auth.ProviderSamples.Helpers.OAuth2;

            if (null == oauth2)
            {
                oauth1 = Activator.CreateInstance(selection_type) as Xamarin.Auth.ProviderSamples.Helpers.OAuth1;

                if (null == oauth1)
                {
                    throw new ArgumentException("Not OAuth object!");
                }

                authenticator = Map(oauth1);
            }

            authenticator = Map(oauth2);

            return;
        }
        public OAuth2Authenticator Map(Xamarin.Auth.ProviderSamples.Helpers.OAuth2 oauth2)
        {
            OAuth2Authenticator o2a = new OAuth2Authenticator
                                      (
                clientId: oauth2.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer,
                clientSecret: oauth2.OAuth_SecretKey_ConsumerSecret_APISecret,
                scope: oauth2.OAuth2_Scope,
                authorizeUrl: oauth2.OAuth_UriAuthorization,
                accessTokenUrl: oauth2.OAuth_UriCallbackAKARedirect,
                redirectUrl: oauth2.OAuth_UriCallbackAKARedirect,
                getUsernameAsync: null,
                isUsingNativeUI: true
                                      );

            System.Diagnostics.Debug.WriteLine(o2a.ToString());

            return(o2a);
        }
        private void Authenticate(Xamarin.Auth.ProviderSamples.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;
        }
        private void Authenticate(Xamarin.Auth.ProviderSamples.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;
        }
        private void Authenticate(Xamarin.Auth.ProviderSamples.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;
        }
Example #6
0
        private void Authenticate(Xamarin.Auth.ProviderSamples.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 #7
0
        private void Authenticate(Xamarin.Auth.ProviderSamples.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)
            {
                InitializeNativeUICustomTabs();
            }

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

            return;
        }