Identityserver4: Scope api1 is not found in store in IdentityServer4 version 4.0.2

Created on 7 Jul 2020  路  5Comments  路  Source: IdentityServer/IdentityServer4

api1 is my api scope. After Identityserver4 is upgraded to version 4.0.2, Identityserver4 always prompts scope api1 is not fund in store when accessing API, but when I downgrade to 3.1.3,it works well.Is it a bug?

question wontfix

Most helpful comment

I was having the same issue

So now you need IdentityResources, ApiResources, Client and now ApiScopes.

Add this to your config

        public static IEnumerable<ApiScope> GetApiScopes()
        {
            return new List<ApiScope>
            {
                // backward compat
                new ApiScope(ApiName)
            };
        } 

Then add AddInMemoryApiScopes on ConfigureServices like so:


                    services.AddIdentityServer()
                                .AddInMemory______
                                .AddInMemory_______
                                .AddInMemoryApiScopes(IdentityServerConfig.GetApiScopes())

All 5 comments

I was having the same issue

So now you need IdentityResources, ApiResources, Client and now ApiScopes.

Add this to your config

        public static IEnumerable<ApiScope> GetApiScopes()
        {
            return new List<ApiScope>
            {
                // backward compat
                new ApiScope(ApiName)
            };
        } 

Then add AddInMemoryApiScopes on ConfigureServices like so:


                    services.AddIdentityServer()
                                .AddInMemory______
                                .AddInMemory_______
                                .AddInMemoryApiScopes(IdentityServerConfig.GetApiScopes())

With 4.x ApiScopes are required and ApiResources are now an optional way of grouping ApiScopes.

ApiScopes - https://identityserver4.readthedocs.io/en/latest/topics/resources.html?highlight=apiscope#scopes
ApiResources - https://identityserver4.readthedocs.io/en/latest/topics/resources.html?highlight=apiscope#api-resources

Thanks.
I realized that, the samples were not updated in the time i downloaded.
Now i got the updated source, and it麓s updated.

Like @bryantlikes introduced, apiScope are now required, and allow more granularity control than the old api resources:
In my code i麓ve updated to this below:

public static IEnumerable<ApiResource> GetApiResources()
        {
            return new List<ApiResource>
            {
                new ApiResource("apiErp", "ERP BACKEND")
                {
                    Scopes = new List<string>()
                    {
                        "apiErp.access"
                    }
                }
            };
        }

        public static IEnumerable<ApiScope> GetApiScopes()
        {
            return new[]
            {
                new ApiScope(name: "apiErp.access",   displayName: "Access API Backend")
            };
        }

// And in Startup.cs

services.AddIdentityServer(isrvconfig =>
                {
                    isrvconfig.Events.RaiseErrorEvents = true;
                    isrvconfig.Events.RaiseInformationEvents = true;
                    isrvconfig.Events.RaiseFailureEvents = true;
                    isrvconfig.Events.RaiseSuccessEvents = true;
                })
                .AddInMemoryIdentityResources(IdentityDevelopmentConfig.GetIdentityResources())
                .AddInMemoryApiResources(IdentityDevelopmentConfig.GetApiResources())
// 馃敶  馃憞
                .AddInMemoryApiScopes(IdentityDevelopmentConfig.GetApiScopes())
                .AddInMemoryClients(IdentityDevelopmentConfig.GetMainClients(configuration))
                .AddAspNetIdentity<AppUser>();

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

createroftheearth picture createroftheearth  路  3Comments

ekarlso picture ekarlso  路  3Comments

leastprivilege picture leastprivilege  路  3Comments

user1336 picture user1336  路  3Comments

agilenut picture agilenut  路  3Comments