0

I've designed my API resource as shown below (in accordance to e.g. this sample). It works and acts as supposed to.

yield return new ApiResource("my_resource")
{
    Scopes = new string[]{ "my_scope" }
};

However, I just noticed that the above is wrong according to the docs, which baffles me. Apparently, it's supposed to be accepting an array of class Scope, not string.

yield return new ApiResource("my_wtf_resource")
{
    Scopes = { new Scope("my_wtf_scope") }
};

That produces an error telling me that it can't convert from string to Scope. Well, du'h... It gets even weirder as I discovered that there is actually a class Scope and it's located in the namespace Microsoft.OpenApi.Writers, which is suspiciously close to security, identity and such.

What's up wth that? Am I confusing something or have the docs people made a boo-boo?

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
  • You might have imported the wrong `ApiResource`. You need [the one in `IdentityServer4.Models`](https://github.com/IdentityServer/IdentityServer4/blob/3ff3b46698f48f164ab1b54d124125d63439f9d0/src/Storage/src/Models/ApiResource.cs#L87). There's also [one in `IdentityServer4.EntityFramework.Entities` namespace](https://github.com/IdentityServer/IdentityServer4/blob/3ff3b46698f48f164ab1b54d124125d63439f9d0/src/EntityFramework.Storage/src/Entities/ApiResource.cs#L21). – abdusco Jul 30 '21 at 06:55
  • @abdusco The only related import for `ApiResource` I have in the class is `using IdentityServer4.Models;`. Can you confirm explicitly that you have the field `Scopes` is of type `ICollection` and not `ICollection` as I do? This is weird... – Konrad Viltersten Jul 30 '21 at 07:05
  • I can't see any `List Scopes` property in the codebase. Docs might be out of date. – abdusco Jul 30 '21 at 07:07
  • Not sure where the official docs are source from, but in the repo, it states "list of scope names", i.e. string https://github.com/IdentityServer/IdentityServer4/blob/3ff3b46698f48f164ab1b54d124125d63439f9d0/docs/reference/api_resource.rst – abdusco Jul 30 '21 at 07:17
  • @abdusco Ha! It certainly an act of aggression against myself in order to confuse me. I knew it... (Anyway, thanks for confirming that. I get so unsure when discrepancies like this pop up, always assuming it's me missing the point due to misfortune thinking. Feel free to summarize this as an answer to be accepted.) – Konrad Viltersten Jul 30 '21 at 11:53

0 Answers0