Пример #1
0
        //<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        //<person>
        //  <id>FQJIJg-u80</id>
        //  <first-name>alexander</first-name>
        //  <last-name>rusanov</last-name>
        //</person>

        public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary <string, string> @params)
        {
            var token = context.Request["oauth_token"];

            if (string.IsNullOrEmpty(token))
            {
                LinkedInConsumer.RequestAuthorization(SignIn);
            }
            else
            {
                var accessTokenResponse = SignIn.ProcessUserAuthorization();
                if (accessTokenResponse != null)
                {
                    //All ok. request info
                    var responce = LinkedInConsumer.GetProfile(SignIn, accessTokenResponse.AccessToken);
                    var document = XDocument.Parse(responce).CreateNavigator();
                    return(new LoginProfile()
                    {
                        Id = document.SelectNodeValue("//id"),
                        FirstName = document.SelectNodeValue("//first-name"),
                        LastName = document.SelectNodeValue("//last-name"),
                        Avatar = document.SelectNodeValue("//picture-url"),
                        Provider = ProviderConstants.LinkedIn
                    });
                }
                return(LoginProfile.FromError(new Exception("Login failed")));
            }
            return(null);
        }
        public LoginProfile ProcessAuthoriztion(HttpContext context, IDictionary <string, string> @params)
        {
            var token = context.Request["oauth_token"];

            if (string.IsNullOrEmpty(token))
            {
                LinkedInConsumer.RequestAuthorization(SignIn);
            }
            else
            {
                var accessTokenResponse = SignIn.ProcessUserAuthorization();
                try
                {
                    return(token == null
                               ? LoginProfile.FromError(new Exception("Login failed"))
                               : RequestProfile(accessTokenResponse.AccessToken));
                }
                catch (Exception ex)
                {
                    return(LoginProfile.FromError(ex));
                }
            }
            return(null);
        }