public virtual async Task <IOAuth1Account> AuthenticateAsync(IOAuth1Options options) { // Set the current expected redirect uri oauth = new OAuth1(options); var url = await oauth.GetInitialUrlAsync(); var svc = new SFSafariViewController(NSUrl.FromString(url.AbsoluteUri)) { Delegate = new NativeSFSafariViewControllerDelegate { DidFinishHandler = (obj) => { tcsAuth.TrySetResult(default(IOAuth1Account)); } } }; tcsAuth = new TaskCompletionSource <IOAuth1Account>(); await Plugin.SocialAuth.iOS.SocialAuth.PresentingViewController.PresentViewControllerAsync(svc, true); return(await tcsAuth.Task); }
public virtual async Task <IOAuth1Account> AuthenticateAsync(IOAuth1Options options) { // Set the current expected redirect uri oauth = new OAuth1(options); var url = await oauth.GetInitialUrlAsync(); tcsAuth = new TaskCompletionSource <IOAuth1Account>(); // DO TABS authSession = new CustomTabsAuthSession(); authSession.AuthTaskCompletionSource = new TaskCompletionSource <IOAuth1Account>(); authSession.ParentActivity = Plugin.SocialAuth.Droid.SocialAuth.CurrentActivity; authSession.CustomTabsActivityManager = new CustomTabsActivityManager(authSession.ParentActivity); authSession.CustomTabsActivityManager.NavigationEvent += (navigationEvent, extras) => { if (navigationEvent == CustomTabsCallback.TabHidden) { if (authSession.AuthTaskCompletionSource != null) { authSession.AuthTaskCompletionSource.TrySetCanceled(); } } }; authSession.CustomTabsActivityManager.CustomTabsServiceConnected += delegate { var ctam = authSession.CustomTabsActivityManager; var ses = ctam.Session; var builder = new CustomTabsIntent.Builder(ses) .SetShowTitle(true); var customTabsIntent = builder.Build(); customTabsIntent.Intent.AddFlags(Android.Content.ActivityFlags.SingleTop | ActivityFlags.NoHistory | ActivityFlags.NewTask); CustomTabsHelper.AddKeepAliveExtra(authSession.ParentActivity, customTabsIntent.Intent); customTabsIntent.LaunchUrl(authSession.ParentActivity, Android.Net.Uri.Parse(url.AbsoluteUri)); }; if (!authSession.CustomTabsActivityManager.BindService()) { tcsAuth.TrySetException(new Exception("CustomTabs not supported.")); } return(await tcsAuth.Task); }