Question

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.

Was it helpful?

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

OTHER TIPS

I had the same Problem. So i checked two things, which solved it for me.

  1. Checking the state queryparam. It has to contain (if you use OAuthWebSecurity) "__provider__=" and "__sid__=". (?__provider__=linkedin&__sid__=987654321)

  2. Checking the appId and appSecret. Notice: Since OAuth2 there are two kinds of "keys" (appId and consumerKey are different). Same for the Secrets.

If you use OAuth2 only the appId and appSecret will work for you. Otherwise for OAuth(1) you have to choose the consumerKey and consumerSecret. (it wont work if you try to use the appId from oauth2 with the consumerSecret you will get the 401 error)

I hope this will solve your problem too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top