error:invalid_scope - IdentityServer Flow.ClientCr

2019-09-15 11:21发布

问题:

I'm having a Client in my IdentityServer3

new Client
{
    ClientName = "Client Credentials Flow Client",
    Enabled = true,
    ClientId = "clientcredentials.reference",
    Flow = Flows.ClientCredentials,

    ClientSecrets = new List<Secret>
    {
        new Secret("secret".Sha256()),
    },

    AllowedScopes = new List<string>()
    {
        "read",
        "write"
    }
}

I hosted the Token Service in my local IIS and I tried to ping the Token using Postman, but it given an error {"error":"invalid_scope"}

Host URL: 
    https://localhost:5775/core/connect/token
Header: 
    Content-Type:application/x-www-form-urlencoded
Body:
    grant_type=client_credentials
    &cliend_id=clientcredentials.reference
    &client_secret=secret

Note: I'm using pure IdentityServer3 package not Thinktecture

回答1:

Check the Scopes "read" and "write" in Scopes declaration

new Scope
{
    Name = "read",
    DisplayName = "Read data",
    Type = ScopeType.Resource,
    Emphasize = false,

    ScopeSecrets = new List<Secret>
    {
        new Secret("secret".Sha256())
    }
},
new Scope
{
    Name = "write",
    DisplayName = "Write data",
    Type = ScopeType.Resource,
    Emphasize = true,

    ScopeSecrets = new List<Secret>
    {
        new Secret("secret".Sha256())
    }
}

I think its missed... Check it once...