Beispiel #1
0
        public bool OpenUrl(UIApplication application, NSUrl url, string sourceApplication, NSObject annotation)
        {
            if (oauth == null || oauth.CallbackUrl == null)
            {
                return(false);
            }

            // Make sure we're redirecting from our SFSafariViewController and not some other app
            if (sourceApplication != "com.apple.SafariViewService")
            {
                return(false);
            }

            var uri = new Uri(url.AbsoluteString);

            // Only handle schemes we expect
            if (!WebUtil.CanHandleCallback(oauth.CallbackUrl, uri))
            {
                return(false);
            }

            var resp = oauth.ParseCallback(uri);

            var waitReq = new System.Threading.ManualResetEventSlim();

            IDictionary <string, string> items = null;

            var accessTokenTask = Task.Run(async() =>
            {
                items = await oauth.GetAccessTokenAsync(resp);
            });

            accessTokenTask.Wait();

            var account = oauth.GetAccountFromResponse <OAuth1Account>(items);

            Plugin.SocialAuth.iOS.SocialAuth.PresentingViewController.InvokeOnMainThread(async() =>
                                                                                         await Plugin.SocialAuth.iOS.SocialAuth.PresentingViewController.DismissViewControllerAsync(true));

            if (account == null)
            {
                tcsAuth?.TrySetException(new Exception("Failed to parse server response."));
            }
            else
            {
                tcsAuth?.TrySetResult(account);
            }

            // Reset oauth for next request
            oauth = null;

            return(true);
        }
        public bool Callback(Intent intent, Bundle state)
        {
            if (authSession == null || intent == null)
            {
                return(false);
            }

            var uri = new Uri(intent.Data.ToString());

            // Only handle schemes we expect
            if (!WebUtil.CanHandleCallback(oauth.CallbackUrl, uri))
            {
                return(false);
            }

            var resp = oauth.ParseCallback(uri);

            IDictionary <string, string> items = null;

            var accessTokenTask = Task.Run(async() =>
            {
                items = await oauth.GetAccessTokenAsync(resp);
            });

            accessTokenTask.Wait();

            var account = oauth.GetAccountFromResponse <OAuth1Account>(items);

            if (account == null)
            {
                tcsAuth?.TrySetException(new Exception("Failed to parse server response."));
            }
            else
            {
                tcsAuth?.TrySetResult(account);
            }

            oauth       = null;
            authSession = null;

            return(true);
        }
        public bool Callback(Intent intent, Bundle state)
        {
            if (authSession == null || intent == null)
            {
                return(false);
            }

            var uri = new Uri(intent.Data.ToString());

            // Only handle schemes we expect
            if (!WebUtil.CanHandleCallback(oauth.RedirectUrl, uri))
            {
                return(false);
            }

            IOAuth2Account account         = null;
            var            accessTokenTask = Task.Run(async() =>
            {
                account = await oauth.ParseCallbackAsync <OAuth2Account>(uri);
            });

            accessTokenTask.Wait();

            if (account == null)
            {
                tcsAuth?.TrySetException(new Exception("Failed to parse server response."));
            }
            else
            {
                tcsAuth?.TrySetResult(account);
            }

            oauth       = null;
            authSession = null;

            return(true);
        }