Пример #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);
        }
        private static LoginProfile RequestProfile(string accessToken)
        {
            var responce = LinkedInConsumer.GetProfile(SignIn, 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
            });
        }