IdentityServer4Demo icon indicating copy to clipboard operation
IdentityServer4Demo copied to clipboard

Breaks with the latest version of Identity Server 4

Open improwise opened this issue 3 years ago • 2 comments

Hi,

Great demo but it breaks once you update Identity Server to latest version, ApiResource more specifically.

Thanks.

Migration steps to v4
As described above, starting with v4, scopes have their own definition and can optionally be referenced by resources. Before v4, scopes where always contained within a resource.

To migrate to v4 you need to split up scope and resource registration, typically by first registering all your scopes (e.g. using the AddInMemoryApiScopes method), and then register the API resources (if any) afterwards. The API resources will then reference the prior registered scopes by name.

improwise avatar Sep 29 '20 12:09 improwise

This probably means that some updates are necessary for the article as well as some of the definitions are not correct any more

https://vmsdurano.com/apiboilerplate-and-identityserver4-access-control-for-apis/

improwise avatar Sep 29 '20 12:09 improwise

So, basically, remove Scope definition from ApiResources, then create a new class with something like this (a bit rough but still)

    internal static class ScopeManager
    {
        public static IEnumerable<ApiScope> Scopes =>
            new List<ApiScope>
            {
                new ApiScope(name: "app.api.whatever.read",   displayName: "Read your data."),
                new ApiScope(name: "app.api.whatever.write",  displayName: "Write your data."),
                new ApiScope(name: "app.api.whatever.delete", displayName: "Delete your data.")
            };
    }

and add in Startup:

.AddInMemoryApiScopes(Data.ScopeManager.Scopes)

improwise avatar Sep 29 '20 13:09 improwise