2015-02-08 49 views
8

我遇到問題,而集成外部提供商,即谷歌與Thinktecture身份服務器v3。我得到以下錯誤:「客戶端應用程序不知道或未被授權。 做任何人有任何關於這個錯誤的想法。Thinktecture Identity server v3谷歌提供商

+0

我有同樣的問題 – akokani 2015-02-10 15:03:48

回答

0

看起來像客戶端(您希望可以使用Google登錄的應用程序)未在客戶端商店中註冊。請問您能否顯示您的啓動配置?

+0

不是我的問題,但我確實有同樣的錯誤。在下面粘貼我的代碼,因爲評論無法實現。 – Whoever 2015-02-27 22:56:02

16

@無論如何,它看起來像在客戶端和服務器上的RedirectUri值不匹配。

客戶端啓動時的RedirectUri屬性定義了在身份服務器進行身份驗證後將被調用的URI。服務器配置中的RedirectUris定義了可以請求認證的允許URI的列表。客戶端啓動RedirectUri必須包含在服務器的RedirectUris列表中。

看起來您的客戶端的RedirectUri目前正指向服務器的URI。您的客戶端是否在端口46289上運行?如果是這樣,請嘗試將客戶端啓動時RedirectUri屬性的值更改爲https://localhost:46289。假設您的客戶端真的可以通過https訪問,您可能還想嘗試修改服務器的redirectUris值以使用https而不是http。

服務器客戶商店:

public static IEnumerable<Client> Get() 
{ 
    return new[] { 
     new Client { 
      Enabled = true, 
      ClientName = "MVC Client", 
      ClientId = "mvc", 
      Flow = Flows.Implicit, 

      RedirectUris = new List<string>{ 
       "https://localhost:46289/" // client home url 

客戶端啓動:

public void Configuration(IAppBuilder app) 
{ 
    ConfigureAuth(app); 
    app.UseCookieAuthentication(new CookieAuthenticationOptions { 
     AuthenticationType = "Cookies"   
    }); 

    app.UseOpenIdConnectAuthentication(
     new OpenIdConnectAuthenticationOptions { 
      Authority = "https://localhost:44300/identity", 
      ClientId = "mvc", 
      RedirectUri = "https://localhost:46289/", //must be in server's Client.RedirectUris 
      ResponseType = "id_token", 

      SignInAsAuthenticationType = "Cookies" 
    }); 
+0

嘗試了兩個,更改重定向uri和https,仍然是相同的錯誤。在添加客戶端相關的nuget包時也注意到,它進行了很多修改,這些修改不在Thinktecture下載的MVC示例中。不知道爲什麼他們將服務器和客戶端代碼放在同一個樣本中,我甚至不知道服務器端和客戶端在哪裏開始,可能錯過了其他地方重要的東西。猜猜我必須回到沒有MVC的更簡單的例子重新開始。謝謝你的幫助。 – Whoever 2015-03-02 20:52:45

+0

你看過http://identityserver.github.io/Documentation/docs/overview/simplestOAuth.html上的示例嗎?這在同一個解決方案中有一個自己託管的服務器,一個web api和一個控制檯。我_think_通過從http://列出的兩個「Getting Started」示例中的每一箇中選擇一個項目,我得到了當前示例(一個自託管服務器和一個IIS中的mvc網站,每個都位於其自己的.sln中) identityserver.github.io/Documentation/docs/,然後做一些微小的調整,例如關閉服務器端的SSL,並按照上文所述調整服務器/客戶端配置中的URI。 – BinaryMash 2015-03-03 22:26:43

+0

是的,我剛剛完成了這一步。它有服務器,Web API和客戶端。但在MVC示例中,它從服務器跳轉到添加cookie和openidconnect軟件包,然後將[授權]添加到控制器。我無法分辨服務器端和客戶端在哪裏開始。我將服務器部分留在一個空項目中,然後創建一個單獨的MVC項目,並從cookie/openid步驟開始,並獲得該客戶端未知錯誤。不知道我是否正確理解整個事情。我現在要回去檢查一下網絡託管的服務器示例,也許是一些個人客戶端。似乎需要學習很多。 – Whoever 2015-03-04 04:20:21

2

我已經工作過同樣的問題,但只是針對身份驗證服務器的身份(谷歌是未來解決我的名單上) 。我看到了這個問題,因爲客戶端的範圍沒有在Mvc和Server上設置。要解決我添加了作用域到啓動類的問題(MVC的客戶端)如下:

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      Authority = "https://localhost:44301", 
      Scope = "openid profile email roles", 
      ClientId = "mvc", 
      RedirectUri = "https://localhost:44300/", 
      ResponseType = "id_token", 

      SignInAsAuthenticationType = "Cookies" 
     }); 

     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AuthenticationType = "Cookies" 
     }); 
    } 
} 

..和也是在客戶端的服務器的列表:

public static class Clients 
{ 
    public static IEnumerable<Client> Get() 
    { 
     return new[] 
     { 
      new Client 
      { 
       Enabled = true, 
       ClientName = "MVC Client", 
       ClientId = "mvc", 
       Flow = Flows.Implicit, 
       RequireConsent = true, 
       RedirectUris = new List<string> 
       { 
        "https://localhost:44300/" 
       }, 
       PostLogoutRedirectUris = new List<string> 
       { 
        "https://localhost:44300/" 
       }, 
       AllowedScopes = new List<string> { 
        Constants.StandardScopes.OpenId, 
        Constants.StandardScopes.Profile, 
        Constants.StandardScopes.Email, 
        Constants.StandardScopes.Roles 
       } 
      } 
     }; 
    } 
} 

在相對於OP向Google提出的問題可能值得檢查一下您的範圍是否與Google開發者控制檯中的應用設置支持的範圍相關。有一個很好的SO張貼在支持範圍在Where can I find a list of scopes for Google's OAuth 2.0 API?

希望幫助:)

6

我有這個問題。服務器中的RedirectUris條目幾乎與在客戶端Startup.Configuration中與RedirectUri匹配;除了最後的斜線外。

https://localhost:46289/ 

是不一樣的

https://localhost:46289 

當我加斜槓,我的登錄頁面出現。

+0

我犯了同樣的錯誤...... :) – 2015-12-03 14:16:30

+0

這個匹配是一個精確的字符串匹配(不區分大小寫),而不是使用Uri類的更聰明的東西! – Lukos 2016-02-02 11:39:20

0

就我而言,我是不小心,並改變Startup.cs UseOpenIdConnectAuthentication下的數值(這是什麼集成的Web應用程序使用連接到它)當我應該已在客戶端改變的值。 Get(),這是服務器配置的允許的客戶端。

一旦我解決了這些問題,我能夠將客戶端和服務器分成兩個應用程序,只有一些NuGet包和UseCookieAuthentication/UseOpenIdConnectAuthentication在客戶端應用程序中。

如果客戶端未啓用,重定向URI不匹配列表中的一個(使用不區分大小寫的精確匹配),請求的作用域不在允許的作用域列表中,如果該流程請求不符合允許的內容(每個客戶端只能有一個)和/或客戶端ID不匹配。