身份服务器收到“错误”:“invalid_scope”

Kod*_*zzz 3 c# asp.net-core identityserver4

我在尝试获取自定义范围值的令牌时遇到错误。下面是我的代码片段。

public static IEnumerable<ApiResource> GetApis() =>
        new List<ApiResource>
        {
             new ApiResource("ApiOne","ApiOne",new []{ "ApiOne"})
        };
public static IEnumerable<Client> GetClients() =>
        new List<Client> { new Client
        {
            ClientId="client1",
            ClientSecrets={ new Secret("secret1".Sha256())},
            AllowedGrantTypes={GrantType.ClientCredentials},
            AllowedScopes={"ApiOne"},
            AllowOfflineAccess=true,
            
        },
        };
Run Code Online (Sandbox Code Playgroud)

Kod*_*zzz 7

在配置中添加 ApiScope

public static List<ApiScope> Get()
    {
        return new List<ApiScope>
       {
           new ApiScope
           {
               Name = "ApiOne",
               Emphasize=true,
           },
           new ApiScope
           {
               Name = "ApiTwo",
               Emphasize=true,
           },
       };
    }
Run Code Online (Sandbox Code Playgroud)

在启动文件中添加

.AddInMemoryApiScopes(Configuration.Get());
Run Code Online (Sandbox Code Playgroud)