void BeginLoadingInitialUrl() { authenticator.GetInitialUrlAsync().ContinueWith(t => { if (t.IsFaulted) { keepTryingAfterError = false; authenticator.OnError(t.Exception); } else { // Delete cookies so we can work with multiple accounts if (this.authenticator.ClearCookiesBeforeLogin) { WebAuthenticator.ClearCookies(); } // // Begin displaying the page // Uri uri = t.Result; LoadInitialUrl(uri); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
public static async void Login(WebAuthenticator authenticator) { var fbAuth = authenticator as FacebookAuthenticator; try { fb.CoreKit.Settings.AppID = fbAuth.ClientId; var loginManager = new fb.LoginKit.LoginManager(); var window = UIKit.UIApplication.SharedApplication.KeyWindow; var root = window.RootViewController; if (root != null) { var current = root; while (current.PresentedViewController != null) { current = current.PresentedViewController; } var resp = await loginManager.LogInWithReadPermissionsAsync(authenticator.Scope.ToArray(), current); if (resp.IsCancelled) { authenticator.OnCancelled(); return; } var date = (DateTime)resp.Token.ExpirationDate; var expiresIn = (long)(date - DateTime.Now).TotalSeconds; fbAuth.OnRecievedAuthCode(resp.Token.TokenString, expiresIn); } } catch (Exception ex) { authenticator.OnError(ex.Message); } }
public static async void Login (WebAuthenticator authenticator) { var fbAuth = authenticator as FacebookAuthenticator; try { fb.CoreKit.Settings.AppID = fbAuth.ClientId; var loginManager = new fb.LoginKit.LoginManager(); var window = UIKit.UIApplication.SharedApplication.KeyWindow; var root = window.RootViewController; if (root != null) { var current = root; while (current.PresentedViewController != null) { current = current.PresentedViewController; } var resp = await loginManager.LogInWithReadPermissionsAsync(authenticator.Scope.ToArray(),current); if (resp.IsCancelled) { authenticator.OnCancelled(); return; } var date = (DateTime)resp.Token.ExpirationDate; var expiresIn = (long)(date - DateTime.Now).TotalSeconds; fbAuth.OnRecievedAuthCode(resp.Token.TokenString,expiresIn); } } catch (Exception ex) { authenticator.OnError(ex.Message); } }
public static async void Login(WebAuthenticator authenticator) { var fbAuth = authenticator as FacebookAuthenticator; try { fb.CoreKit.Settings.AppId = fbAuth.ClientId; var loginManager = new fb.LoginKit.LoginManager(); var window = UIKit.UIApplication.SharedApplication.KeyWindow; var root = window.RootViewController; if (root != null) { var current = root; while (current.PresentedViewController != null) { current = current.PresentedViewController; } var tcs = new TaskCompletionSource <LoginManagerLoginResult> (); loginManager.LogIn(authenticator.Scope.ToArray(), current, (LoginManagerLoginResult result, NSError error) => { if (error != null) { tcs.TrySetException(new Exception(error.LocalizedDescription)); } else { tcs.SetResult(result); } }); var resp = await tcs.Task; if (resp.IsCancelled) { authenticator.OnCancelled(); return; } var date = (DateTime)resp.Token.ExpirationDate; var expiresIn = (long)(date - DateTime.Now).TotalSeconds; fbAuth.OnRecievedAuthCode(resp.Token.TokenString, expiresIn); } } catch (Exception ex) { authenticator.OnError(ex.Message); } }
static async void Login(WebAuthenticator authenticator) { currentHandler?.Cancel(); try { currentHandler = new NativeHandler(); var gAuth = authenticator as GoogleAuthenticator; var user = await currentHandler.Authenticate(gAuth); gAuth.ServerToken = user.ServerAuthCode; gAuth.IdToken = user.Authentication.IdToken; gAuth.RefreshToken = user.Authentication.RefreshToken; gAuth.OnRecievedAuthCode(user.Authentication.AccessToken); } catch (TaskCanceledException) { authenticator?.OnCancelled(); } catch (Exception ex) { Console.WriteLine(ex); authenticator.OnError(ex.Message); } }
public static async void Login(WebAuthenticator authenticator, Action <WebAuthenticator> fallback) { var ta = authenticator as TwitterAuthenticator; var scheme = $"twitterkit-{ta.ClientId}"; if (!NativeSafariAuthenticator.VerifyHasUrlSchemeOrDoesntRequire(scheme)) { authenticator.OnError($"Unable to redirect {scheme}, Please add the Url Scheme to the info.plist"); return; } var returnUrl = HttpUtility.UrlEncode($"{scheme}://{ta.Identifier}"); var nativeUrl = new NSUrl($"twitterauth://authorize?consumer_key={ta.ClientId}&consumer_secret={ta.ClientSecret}&oauth_callback={returnUrl}"); if (UIApplication.SharedApplication.CanOpenUrl(nativeUrl)) { if ((await UIApplication.SharedApplication.OpenUrlAsync(nativeUrl, new UIApplicationOpenUrlOptions()))) { CurrentAuthenticators[ta.Identifier] = ta; return; } } fallback(authenticator); }