void OpenUrl(string url) { var sfViewController = new SafariServices.SFSafariViewController(new NSUrl(url)); sfViewController.View.TintColor = BeerDrinkin.Helpers.Colours.Blue.ToNative(); sfViewController.View.BackgroundColor = BeerDrinkin.Helpers.Colours.Blue.ToNative(); PresentViewControllerAsync(sfViewController, true); }
public Task <BrowserResult> InvokeAsync(BrowserOptions options) { if (string.IsNullOrWhiteSpace(options.StartUrl)) { throw new ArgumentException("Missing StartUrl", nameof(options)); } if (string.IsNullOrWhiteSpace(options.EndUrl)) { throw new ArgumentException("Missing EndUrl", nameof(options)); } // must be able to wait for the intent to be finished to continue // with setting the task result var tcs = new TaskCompletionSource <BrowserResult>(); // create Safari controller _safari = new SafariServices.SFSafariViewController(new NSUrl(options.StartUrl)); _safari.Delegate = this; ActivityMediator.MessageReceivedEventHandler callback = null; callback = async(response) => { // remove handler ActivityMediator.Instance.ActivityMessageReceived -= callback; if (response == "UserCancel") { tcs.SetResult(new BrowserResult { ResultType = BrowserResultType.UserCancel }); } else { // Close Safari await _safari.DismissViewControllerAsync(true); // set result tcs.SetResult(new BrowserResult { Response = response, ResultType = BrowserResultType.Success }); } }; // attach handler ActivityMediator.Instance.ActivityMessageReceived += callback; // launch Safari _controller.PresentViewController(_safari, true, null); // need an intent to be triggered when browsing to the "io.identitymodel.native://callback" // scheme/URI => CallbackInterceptorActivity return(tcs.Task); }
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; }
private void Authenticate(Xamarin.Auth.Helpers.OAuth1 oauth1) { // Step 1.1 Creating and configuring an Authenticator Auth1 = new OAuth1Authenticator ( consumerKey: oauth1.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, consumerSecret: oauth1.OAuth1_SecretKey_ConsumerSecret_APISecret, requestTokenUrl: oauth1.OAuth1_UriRequestToken, authorizeUrl: oauth1.OAuth_UriAuthorization, accessTokenUrl: oauth1.OAuth_UriAccessToken_UriRequestToken, callbackUrl: oauth1.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 = oauth1.AllowCancel, }; // Step 1.2 Subscribing to Authenticator events // If authorization succeeds or is canceled, .Completed will be fired. Auth1.Completed += Auth_Completed; Auth1.Error += Auth_Error; Auth1.BrowsingCompleted += Auth_BrowsingCompleted; // Step 2.1 Creating Login UI UIKit.UIViewController ui_object = Auth1.GetUI(); if (Auth1.IsUsingNativeUI == true) { // Step 2.1 Creating Login UI // 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] if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { c.PreferredBarTintColor = color_xamarin_blue; c.PreferredControlTintColor = UIColor.White; } else { c.View.TintColor = color_xamarin_blue; } Action view_controller_customization = () => { c.NavigationController.NavigationBar.TintColor = color_xamarin_blue; }; // Step 3 Present/Launch the Login UI PresentViewController(c, true, view_controller_customization); } else { // Step 3 Present/Launch the Login UI PresentViewController(ui_object, true, null); } 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; }
private void Authenticate(Xamarin.Auth.Helpers.OAuth1 oauth1) { //------------------------------------------------------------- // WalkThrough Step 1 // setting up Authenticator object Auth1 = new OAuth1Authenticator ( consumerKey: oauth1.OAuth_IdApplication_IdAPI_KeyAPI_IdClient_IdCustomer, consumerSecret: oauth1.OAuth1_SecretKey_ConsumerSecret_APISecret, requestTokenUrl: oauth1.OAuth1_UriRequestToken, authorizeUrl: oauth1.OAuth_UriAuthorization, accessTokenUrl: oauth1.OAuth_UriAccessToken_UriRequestToken, callbackUrl: oauth1.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 = oauth1.AllowCancel, }; //------------------------------------------------------------- // If authorization succeeds or is canceled, .Completed will be fired. Auth1.Completed += Auth_Completed; Auth1.Error += Auth_Error; Auth1.BrowsingCompleted += Auth_BrowsingCompleted; //##################################################################### // 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 = Auth1.GetUI(); if (Auth1.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; // 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.2 // UI Customisation // [OPTIONAL] if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) { c.PreferredBarTintColor = color_xamarin_blue; c.PreferredControlTintColor = UIColor.White; } else { c.View.TintColor = color_xamarin_blue; } Action view_controller_customization = () => { c.NavigationController.NavigationBar.TintColor = color_xamarin_blue; }; //------------------------------------------------------------ //------------------------------------------------------------ // WalkThrough Step 3 // Launching UI // [REQUIRED] PresentViewController(c, true, view_controller_customization); //------------------------------------------------------------ //================================================================= } else { //================================================================= // WalkThrough Step 2.1 // casting UI object to proper type to work with // // Xamarin.Auth API - Embedded Browsers support // - Android - Intent to start Activity with WebView // - iOS - UIViewController with UIWebView or WKWebView // // on 2014-04-20 google (and some other providers) will work only with this API // // 2017-03-25 // soon to be non-default // optional API in the future (for backward compatibility) // //------------------------------------------------------------ //------------------------------------------------------------ // WalkThrough Step 3 // Launching UI // [REQUIRED] PresentViewController(ui_object, true, null); //================================================================= } //##################################################################### return; }