Search code examples
asp.net-mvclinkedin-api

Asp.Net MVC: LinkedIn The remote server returned an error: (401) Unauthorized


AuthConfig.cs

public static class AuthConfig
    {
        public static void RegisterAuth()
        {
            OAuthWebSecurity.RegisterLinkedInClient(
               consumerKey: "xxxxxxxxxxx",
               consumerSecret: "xxxxxxxxxx");

            OAuthWebSecurity.RegisterFacebookClient(
                appId: "xxxxxxxxxx",
                appSecret: "xxxxxxxxxxxxxxxxxxxx");
        }
    }

Account Controller ExternalLoginCallback Method

public class AccountController : Controller
    {
      [AllowAnonymous]
            public ActionResult ExternalLoginCallback(string returnUrl)
            {

                AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl })); ;
    }
}

enter image description here I am getting this error: (401) Unauthorized(whenever I am logging in from LinkedIn).However,in case of facebook,it is working fine.Please help me with some soln.


Solution

  • This could help you identify the source of your problem

    Use this OAuth test console and compare the header that you're generating to the one that this tool generates: https://developer.linkedin.com/oauth-test-console If your header is wrong, then LinkedIn will return a 401 status