2014-04-14 25 views
0

這可能會是一個可怕的問題,但我不知道從哪裏開始解決這個問題。我沒有觸及集成LinkedIn與我的webapp的任何代碼,但它只是開始拋出無效的重定向uri錯誤。我正在使用this stuff在我的應用程序中獲取linkedIn。這裏是我的startup.auth.cs文件(顯然鍵屏蔽):LinkedIn在asp.net中的oauth mvc5應用程序停止工作

public void ConfigureAuth(IAppBuilder app) 
    { 
     app.UseCookieAuthentication(options: new CookieAuthenticationOptions 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      ExpireTimeSpan = new TimeSpan(0,0,30,0), 
      LoginPath = new PathString("/Account/Access"), 

     }); 
     app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 

     var linkedInOptions = new LinkedInAuthenticationOptions 
      { 
       ClientId = "fooooooooo", 
       ClientSecret = "barrrrrrrr", 

       Provider = new LinkedInAuthenticationProvider 
        { 

         OnAuthenticated = context => 
          { 
           context.Identity.AddClaim(new Claim("LinkedInAccessToken", context.AccessToken)); 
           return Task.FromResult(0); 
          } 
        } 
      }; 
     linkedInOptions.Scope.Add("r_fullprofile"); 
     app.UseLinkedInAuthentication(linkedInOptions); 
    } 

在我的帳戶控制器這是它打它得到錯誤信息之前:

[HttpPost] 
    [AllowAnonymous] 
    [ValidateAntiForgeryToken] 
    public ActionResult ExternalLogin(string provider, string returnUrl) 
    { 
     // Request a redirect to the external login provider 
     return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { returnUrl })); 
    } 

中,變量「 RETURNURL」爲空,但低於redirectUri是‘/帳號/ ExternalLoginCallback’

private class ChallengeResult : HttpUnauthorizedResult 
    { 
     public ChallengeResult(string provider, string redirectUri) 
      : this(provider, redirectUri, null) 
     { 
     } 

     public ChallengeResult(string provider, string redirectUri, string userId) 
     { 
      LoginProvider = provider; 
      RedirectUri = redirectUri; 
      UserId = userId; 
     } 

     public string LoginProvider { get; set; } 
     public string RedirectUri { get; set; } 
     public string UserId { get; set; } 

     public override void ExecuteResult(ControllerContext context) 
     { 
      var properties = new AuthenticationProperties() { RedirectUri = RedirectUri }; 
      if (UserId != null) 
      { 
       properties.Dictionary[XsrfKey] = UserId; 
      } 
      context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider); 
     } 
    } 

有什麼你看到的可能是有問題的?我應該查看哪些字段以解決此錯誤?當我搜索錯誤時,它只是提供了有關在linkedin上創建應用程序的通用答案,我已經這樣做了。

回答

1

看起來像他們採取的安全措施有一個更新(該死的心情)。需要按照步驟here

簡版:指定您設置linkedin應用程序時的絕對回報URL。

3

我遇到了與您有關的問題。正如你自己在amswer中所說的那樣,在Linkedin中更新之後,你將不得不「指定你的絕對回報網址......」。在我的情況下,問題是要找出Linkedin的確切「返回網址」。


在我的測試中,嘗試使用不同的重定向URL,我注意到Linkedin的響應中顯示的錯誤消息,最後我發現在HTTP響應的參數「request_uri」中添加了字符串「signin-linkedin」(就好像他們期待那樣)。

所以我終於通過將該字符串添加到我的原始URL來解決了問題。如下圖所示:

OAuth 2.0 Redirect URLs form in Linkedin apps

+0

謝謝!這就是我需要的! –