2014-05-05 188 views
3

AuthConfig.csAsp.Net MVC:LinkedIn远程服务器返回错误:(401)未经授权

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

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

账户控制器ExternalLoginCallback方法

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

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

enter image description here 我得到这个错误:( 401)未经授权(每当我从LinkedIn登录时)。但是,如果是Facebook,它工作正常。请帮我解决一些问题。

+0

具有相同的问题。 –

+0

我有同样的问题。 – kat1330

回答

0

我有同样的问题。所以我检查了两件事,为我解决了这个问题。

  1. 检查状态queryparam。它必须包含(如果您使用OAuthWebSecurity)“__provider __ =”和“__sid __ =”。 (?__ provider __ = linkedin & __sid __ = 987654321)

  2. 检查appId和appSecret。注意:由于OAuth2有两种“密钥”(appId和consumerKey不同)。相同的秘密。

如果您使用OAuth2,则只有appId和appSecret可以为您工作。否则,对于OAuth(1),您必须选择consumerKey和consumerSecret。 (它不会工作,如果你尝试使用appId从oauth2与consumerSecret你会得到401错误)

我希望这也能解决你的问题。

相关问题