如果你正在網上找IdentityServer4的學習資料進行學習,發現在請求token的時候一直報
{"error":"invalid_scope"}錯誤
有一個原因可能就是因為你沒有加scope
IdentityServer4 4.x版本跟老版本有些區別,可能你的學習資料還是老的
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(Config.GetResource())
.AddInMemoryClients(Config.GetClients())
.AddInMemoryApiScopes(Config.ApiScopes) //這個方法是新加的
.AddTestUsers(Config.GetTestUsers());`
public static IEnumerable<ApiResource> GetResource()
{
return new List<ApiResource>() {
new ApiResource(MemoryClient.adminFont, "font"){ /*這個一定要加
*/ Scopes = { MemoryScope.menu,MemoryScope.person }}
};
}
然后就能繼續愉快的學習了