private void Authenticate(Xamarin.Auth._MobileServices.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; }
public void AuthenticateOAuth2(Xamarin.Auth._MobileServices.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 Authenticate(Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth2) { OAuth2Authenticator auth = null; if (oauth2.OAuth2_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.OAuth2_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._MobileServices.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._MobileServices.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._MobileServices.CustomTabsConfiguration.AreAnimationsUsed = true; Xamarin.Auth._MobileServices.CustomTabsConfiguration.IsShowTitleUsed = false; Xamarin.Auth._MobileServices.CustomTabsConfiguration.IsUrlBarHidingUsed = false; Xamarin.Auth._MobileServices.CustomTabsConfiguration.IsCloseButtonIconUsed = false; Xamarin.Auth._MobileServices.CustomTabsConfiguration.IsActionButtonUsed = false; Xamarin.Auth._MobileServices.CustomTabsConfiguration.IsActionBarToolbarIconUsed = false; Xamarin.Auth._MobileServices.CustomTabsConfiguration.IsDefaultShareMenuItemUsed = false; Xamarin.Auth._MobileServices.CustomTabsConfiguration.MenuItemTitle = null; Xamarin.Auth._MobileServices.CustomTabsConfiguration.ToolbarColor = global::Android.Graphics.Color.Orange; } // Step 3 Present/Launch the Login UI StartActivity(ui_object); return; }
private void Authenticate(Xamarin.Auth._MobileServices.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; }
private void Authenticate(Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth2) { if (oauth2.OAuth2_UriRequestToken == null || string.IsNullOrEmpty(oauth2.OAuth_SecretKey_ConsumerSecret_APISecret)) { //------------------------------------------------------------- // 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 { //------------------------------------------------------------- // 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.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 ) { 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; }
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._MobileServices.Helpers.OAuth2 oauth_facebook = null; oauth_facebook = Data.TestCases [provider] as Xamarin.Auth._MobileServices.Helpers.OAuth2; AuthenticateOAuth2(oauth_facebook); break; case "Twitter OAuth1": Xamarin.Auth._MobileServices.Helpers.OAuth1 oauth_twitter = null; oauth_twitter = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth1; AuthenticateOAuth1(oauth_twitter); break; case "Google OAuth2": Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth_google = null; oauth_google = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth2; AuthenticateOAuth2(oauth_google); break; case "Microsoft Live OAuth2": Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth_mslive = null; oauth_mslive = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth2; AuthenticateOAuth2(oauth_mslive); break; case "LinkedIn OAuth1": Xamarin.Auth._MobileServices.Helpers.OAuth1 oauth_linkedin1 = null; oauth_linkedin1 = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth1; AuthenticateOAuth1(oauth_linkedin1); break; case "LinkedIn OAuth2": Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth_linkedin2 = null; oauth_linkedin2 = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth2; AuthenticateOAuth2(oauth_linkedin2); break; case "Github OAuth2": Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth_github = null; oauth_github = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth2; AuthenticateOAuth2(oauth_github); break; case "Instagram OAuth2": Xamarin.Auth._MobileServices.Helpers.OAuth2 oauth_instagram = null; oauth_instagram = Data.TestCases[provider] as Xamarin.Auth._MobileServices.Helpers.OAuth2; AuthenticateOAuth2(oauth_instagram); break; default: DisplayAlert("Error", "Unknown OAuth Provider!", "OK"); break; } ; this.Navigation.PushAsync(page); return; }
private void Authenticate(Xamarin.Auth._MobileServices.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; }