【问题标题】:Identity Server Getting "error": "invalid_scope"身份服务器出现“错误”:“invalid_scope”
【发布时间】:2020-06-22 14:02:41
【问题描述】:

我在尝试获取自定义范围值的令牌时出错。下面是我的代码 sn-p。

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,
            
        },
        };

【问题讨论】:

  • 您的客户端配置是什么?
  • 你在定义 API 的范围吗?

标签: c# asp.net-core identityserver4


【解决方案1】:

在配置中添加 ApiScope

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

在启动文件中添加

.AddInMemoryApiScopes(Configuration.Get());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-15
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2018-01-09
    • 2021-06-01
    相关资源
    最近更新 更多