Пример #1
0
        async void ProcessRequest(string url)
        {
            if (url.Contains(NotSensitive.SystemUrls.linkedin_redirect_url))
            {
                var separatedByQuestionMark = url.Split('?').Last();
                var separatedByAmpersand    = separatedByQuestionMark.Split('&');
                foreach (string sub in separatedByAmpersand)
                {
                    if (sub.Contains("code="))
                    {
                        var seperatedByEquals = sub.Split('=');
                        var token             = seperatedByEquals.Last();
                        if (!String.IsNullOrEmpty(token))
                        {
                            ShowHud(Strings.Hud.please_wait);

                            var result = await LinkedInAuthenticator.GetLinkedInAccount(token);

                            if (result != null)
                            {
                                var activity = Activity as BaseActivity;
                                activity?.PopFragmentOverUntil(typeof(MyOutletsRecyclerViewFragment));
                            }

                            HideHud();
                        }
                    }
                }
            }
        }
Пример #2
0
 protected override void OnLoad(EventArgs e)
 {
     base.OnLoad(e);
     try
     {
         LinkedInConfig    linkedInConfig          = this.ReadConfiguration();
         LinkedInAppConfig config                  = this.ReadAppConfiguration();
         LinkedInAppAuthorizationResponse response = new LinkedInAuthenticator(linkedInConfig, new LinkedInWebClient(config, LinkedInSetup.Tracer), LinkedInSetup.Tracer).AuthorizeApplication(base.Request.QueryString, base.Request.Cookies, base.Response.Cookies, this.GetAuthorizationCallbackUrl());
         this.ProcessAuthorizationResponse(response);
     }
     catch (ExchangeConfigurationException ex)
     {
         EcpEventLogConstants.Tuple_BadLinkedInConfiguration.LogPeriodicEvent(EcpEventLogExtensions.GetPeriodicKeyPerUser(), new object[]
         {
             EcpEventLogExtensions.GetUserNameToLog(),
             ex
         });
         ErrorHandlingUtil.TransferToErrorPage("badlinkedinconfiguration");
     }
     catch (LinkedInAuthenticationException ex2)
     {
         EcpEventLogConstants.Tuple_LinkedInAuthorizationError.LogEvent(new object[]
         {
             EcpEventLogExtensions.GetUserNameToLog(),
             ex2
         });
         ErrorHandlingUtil.TransferToErrorPage("linkedinauthorizationerror");
     }
 }
Пример #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            RemoveBackBarButtonTitle();

            //clear cache
            WebUtils.ClearCache();

            //clear cookies
            WebUtils.ClearCookies();

            string AuthorizeUrl = "https://www.linkedin.com/uas/oauth2/authorization?";

            AuthorizeUrl += "response_type=code&";
            AuthorizeUrl += "client_id=" + NotSensitive.SlinkKeys.linkedin_client_id + "&";
            AuthorizeUrl += "redirect_uri=" + NotSensitive.SystemUrls.linkedin_redirect_url + "&";
            AuthorizeUrl += "scope=" + "r_basicprofile" + "&";
            AuthorizeUrl += "state=" + "SLINKNILS";
            Console.WriteLine(AuthorizeUrl);

            var webViewDelegate = new LinkedInWebViewDelegate();

            webViewDelegate.TokenReceived += async(token) =>
            {
                ShowHud(Strings.Hud.please_wait);

                var result = await LinkedInAuthenticator.GetLinkedInAccount(token);

                if (result != null)
                {
                    var popToViewController = NavigationController.ViewControllers.Where(c => c.GetType() == typeof(MyOutletsViewController)).First();
                    NavigationController.PopToViewController(popToViewController, true);
                }

                HideHud();
            };

            var request = new NSMutableUrlRequest(NSUrl.FromString(AuthorizeUrl), NSUrlRequestCachePolicy.ReloadIgnoringLocalCacheData, 10);

            //do not uncomment. LinkedIn doesnt work without cookies
            //request.ShouldHandleCookies = false;

            var offsetY = NavigationController.NavigationBar.Bounds.Height;

            WebView          = new UIWebView(new CGRect(0, offsetY, View.Bounds.Width, View.Bounds.Height - offsetY));
            WebView.Delegate = webViewDelegate;
            WebView.LoadRequest(request);
            View.AddSubview(WebView);
            View.AddConstraint(NSLayoutConstraint.Create(WebView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, View, NSLayoutAttribute.Top, 1, offsetY));
            View.AddConstraint(NSLayoutConstraint.Create(WebView, NSLayoutAttribute.Right, NSLayoutRelation.Equal, View, NSLayoutAttribute.Right, 1, 0));
            View.AddConstraint(NSLayoutConstraint.Create(WebView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1, 0));
            View.AddConstraint(NSLayoutConstraint.Create(WebView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, View, NSLayoutAttribute.Left, 1, 0));
        }