我正在編寫IdentityServer4實現並使用快速入門項目here。爲什麼我在IdentityServer4的同意屏幕上看到重複的範圍?
當您定義一個ApiResource(現在使用InMemory類)時,它看起來像IdentityServer創建一個與資源同名的Scope。例如
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("api", "My API")
};
}
將創建一個名爲「API」的範圍(這是在ApiResource構造函數中完成的)。如果我在客戶端對象上使用「api」作爲允許的範圍(使用InMemoryClients作爲概念證明),並在我的JavaScript客戶端的身份驗證請求中的作用域查詢字符串參數中請求此作用域,我會收到invalid_scope錯誤消息。
我發現以下this documentation您可以通過作用域屬性,像這樣
new ApiResource
{
Name = "api",
DisplayName = "Custom API",
Scopes = new List<Scope>
{
new Scope("api.read"),
new Scope("api.write")
}
}
添加作用域到ApiResource所以現在,如果我不是定義我ApiResource這樣並請求作用域api.read和api.write (並將它們添加到客戶端對象上的AllowedScopes屬性),那麼一切正常,除了顯示重複範圍的同意頁面。它顯示了2次api.read和api.write 2次。看到這裏
同意畫面客戶端配置如下:
new Client
{
ClientId = "client.implicit",
ClientName = "JavaScript Client",
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
RedirectUris = { "http://localhost:3000/health-check" },
PostLogoutRedirectUris = { "http://localhost:3000" },
AllowedCorsOrigins = { "http://localhost:3000" },
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"customApi.read", "customApi.write"
}
}
這究竟是爲什麼?我做了什麼明顯錯誤?
更新: 這裏發現的文件,顯示範圍是隻列出一次的一部分...
你有多少API資源?他們的範圍將被複制。請考慮從'/ .well-known/openid-configuration'端點發布'scopes_supported'內容。 –
@IlyaChumakov我發佈了它。我絕對只有一個API資源,所以我迷失在爲什麼會發生這種情況 –