GetInitialUrl() public method

public GetInitialUrl ( ) : Task
return Task
Beispiel #1
0
 static async Task BeginAuthentication(WebAuthenticator authenticator)
 {
     try {
         var    uri         = (await authenticator.GetInitialUrl());
         string redirectUrl = uri.GetParameter("redirect_uri");
         var    scheme      = new Uri(redirectUrl).Scheme;
         if (!VerifyHasUrlScheme(scheme))
         {
             authenticator.OnError($"Unable to redirect {redirectUrl}, Please add the Url Scheme to the info.plist");
             return;
         }
         var url    = new NSUrl(uri.AbsoluteUri);
         var opened = NSWorkspace.SharedWorkspace.OpenUrl(url);
         if (!opened)
         {
             authenticator.OnError("Error opening Safari");
         }
         else
         {
             authenticators [scheme] = authenticator;
         }
     } catch (Exception ex) {
         authenticator.OnError(ex.Message);
     }
 }
        static async Task BeginAuthentication(UIViewController presentingController, WebAuthenticator authenticator)
        {
            try {
                var    uri         = (await authenticator.GetInitialUrl());
                string redirectUrl = uri.GetParameter("redirect_uri");
                var    scheme      = new Uri(redirectUrl).Scheme;
                if (!VerifyHasUrlSchemeOrDoesntRequire(scheme))
                {
                    authenticator.OnError($"Unable to redirect {scheme}, Please add the Url Scheme to the info.plist");
                    return;
                }
                var url = new NSUrl(uri.AbsoluteUri);
                if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
                {
                    var AuthTask = new TaskCompletionSource <object>();
                    authenticators[scheme] = authenticator;
                    var sf = new SFAuthenticationSession(url, scheme,
                                                         (callbackUrl, Error) => {
                        if (Error == null)
                        {
                            ResumeAuth(callbackUrl.AbsoluteString);
                            AuthTask.SetResult(null);
                        }
                        else
                        {
                            AuthTask.SetException(new Exception($"SFAuthenticationSession Error: {Error.ToString()}"));
                        }
                    }
                                                         );
                    sf.Start();
                    await AuthTask.Task;
                    return;
                }

                if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    var controller = new SFSafariViewController(url, false)
                    {
                        Delegate = new NativeSFSafariViewControllerDelegate(authenticator),
                    };
                    authenticators [scheme] = authenticator;
                    CurrentController       = controller;
                    await presentingController.PresentViewControllerAsync(controller, true);

                    return;
                }

                var opened = UIApplication.SharedApplication.OpenUrl(url);
                if (!opened)
                {
                    authenticator.OnError("Error opening Safari");
                }
                else
                {
                    authenticators [scheme] = authenticator;
                }
            } catch (Exception ex) {
                authenticator.OnError(ex.Message);
            }
        }
Beispiel #3
0
        static async Task BeginAuthentication(WebAuthenticator authenticator)
        {
            try
            {
                var    uri         = (await authenticator.GetInitialUrl());
                string redirectUrl = uri.GetParameter("redirect_uri");
                var    scheme      = new Uri(redirectUrl).Scheme;

                var authSession = new CustomTabsAuthSession
                {
                    Authenticator  = authenticator,
                    ParentActivity = activityLifecycleManager.CurrentActivity,
                };

                authenticators[scheme] = authSession;
                authSession.CustomTabsActivityManager = new CustomTabsActivityManager(authSession.ParentActivity);
                authSession.CustomTabsActivityManager.CustomTabsServiceConnected += delegate
                {
                    var builder = new CustomTabsIntent.Builder(authSession.CustomTabsActivityManager.Session)
                                  .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(uri.AbsoluteUri));
                };

                if (!authSession.CustomTabsActivityManager.BindService())
                {
                    authenticator.OnError("CustomTabs not supported.");
                    authenticators.Remove(scheme);
                }
            }
            catch (Exception ex)
            {
                authenticator.OnError(ex.Message);
            }
        }
Beispiel #4
0
        static async Task BeginAuthentication(UIViewController presentingController, WebAuthenticator authenticator)
        {
            try {
                var    uri         = (await authenticator.GetInitialUrl());
                string redirectUrl = uri.GetParameter("redirect_uri");
                var    scheme      = new Uri(redirectUrl).Scheme;
                if (!VerifyHasUrlScheme(scheme))
                {
                    authenticator.OnError($"Unable to redirect {redirectUrl}, Please add the Url Scheme to the info.plist");
                    return;
                }
                var url = new NSUrl(uri.AbsoluteUri);
                if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
                {
                    var controller = new SFSafariViewController(url, false)
                    {
                        Delegate = new NativeSFSafariViewControllerDelegate(authenticator),
                    };
                    authenticators [scheme] = authenticator;
                    CurrentController       = controller;
                    await presentingController.PresentViewControllerAsync(controller, true);

                    return;
                }

                var opened = UIApplication.SharedApplication.OpenUrl(url);
                if (!opened)
                {
                    authenticator.OnError("Error opening Safari");
                }
                else
                {
                    authenticators [scheme] = authenticator;
                }
            } catch (Exception ex) {
                authenticator.OnError(ex.Message);
            }
        }
        public async Task GetCredentials(string title, string details = "")
        {
            try
            {
                var url = await authenticator.GetInitialUrl();

                Console.WriteLine("******************");
                Console.WriteLine(title);
                Console.WriteLine(details);
                Console.WriteLine($"Launching Url: \"{url}\"");
                Console.WriteLine("******************");
                Console.WriteLine("Paste the Redirected URL Here:");
                OpenBrowser(url);
                var username = Console.ReadLine();

                try
                {
                    bool success = false;
                    var  basic   = authenticator;
                    if (basic != null)
                    {
                        success = basic.CheckUrl(new Uri(username), null);
                    }
                    if (!success)
                    {
                        throw new Exception("Invalid Credentials");
                    }
                }
                catch (Exception ex)
                {
                    await GetCredentials(title, $"Error: {ex.Message}");
                }
            }
            catch (TaskCanceledException)
            {
                authenticator.OnCancelled();
            }
        }