title: After updating the identity server 4 4.0.0 from 3.1.4 Scope is invalid asp.net core 3 with Mongo DB
body: <p>In the discovery document, the scope <strong>IdentityPortal.API</strong> is not added</p>
  <pre><code>{
      &quot;issuer&quot;: &quot;https://localhost:5001&quot;,
      &quot;scopes_supported&quot;: [&quot;profile&quot;, &quot;openid&quot;, &quot;email&quot;, &quot;offline_access&quot;],   
  }
  </code></pre>
  <p>However, allowed scope in the config is as below</p>
  <pre><code>private static string apiScope = &quot;IdentityPortal.API&quot;;
  private static ICollection&lt;string&gt; AllowedScopes()
          {
              return new List&lt;string&gt;
              {
                  IdentityServerConstants.StandardScopes.OpenId,
                  IdentityServerConstants.StandardScopes.Profile,
                  IdentityServerConstants.StandardScopes.Email,
                  apiScope
              };
          }
  </code></pre>
  <p>API Resource</p>
  <pre><code>   public static IEnumerable&lt;ApiResource&gt; GetApiResources()
          {
              return new List&lt;ApiResource&gt;
              {
                  new ApiResource(apiScope, &quot;Falcon Api&quot;)
                  {
                      Scopes = new List&lt;string&gt;{apiScope},
                      UserClaims =
                      {
                          JwtClaimTypes.Profile,
                          JwtClaimTypes.Name,
                          JwtClaimTypes.Email,
                      }
                  }
              };
          }
  </code></pre>
  <p>From the React Application I am sending scope as below</p>
  <pre><code> scope: &quot;profile openid email IdentityPortal.API offline_access&quot;,
  </code></pre>
  <p>In the identity server <strong>IdentityPortal.API</strong> is not added as supported claim.</p>
  <p>Here is the <strong>customPersistedGrantStore.cs</strong></p>
  <pre><code>public class CustomResourceStore : IResourceStore
  {
      protected IRepository _dbRepository;
  
      public CustomResourceStore(IRepository repository)
      {
          _dbRepository = repository;
      }
  
  
      public Task&lt;IEnumerable&lt;IdentityResource&gt;&gt; FindIdentityResourcesByScopeNameAsync(IEnumerable&lt;string&gt; scopeNames)
      {
          var list = _dbRepository.Where&lt;IdentityResource&gt;(e =&gt; scopeNames.Contains(e.Name));
          return Task.FromResult(list.AsEnumerable());
      }
  
      public Task&lt;IEnumerable&lt;ApiScope&gt;&gt; FindApiScopesByNameAsync(IEnumerable&lt;string&gt; scopeNames)
      {
          var list = _dbRepository.Where&lt;ApiScope&gt;(a =&gt; scopeNames.Contains(a.Name));
          return Task.FromResult(list.AsEnumerable());
      }
  
      public Task&lt;IEnumerable&lt;ApiResource&gt;&gt; FindApiResourcesByScopeNameAsync(IEnumerable&lt;string&gt; scopeNames)
      {
          var list = _dbRepository.Where&lt;ApiResource&gt;(a =&gt; a.Scopes.Any(s =&gt; scopeNames.Contains(s)));
          return Task.FromResult(list.AsEnumerable());
      }
  
      public Task&lt;IEnumerable&lt;ApiResource&gt;&gt; FindApiResourcesByNameAsync(IEnumerable&lt;string&gt; apiResourceNames)
      {
          var list = _dbRepository.Where&lt;ApiResource&gt;(a =&gt; apiResourceNames.Contains(a.Name));
          return Task.FromResult(list.AsEnumerable());
      }
  
      public Task&lt;Resources&gt; GetAllResourcesAsync()
      {
          var result = new Resources(GetAllIdentityResources(), GetAllApiResources(),null);
          return Task.FromResult(result);
      }
      
      private IEnumerable&lt;IdentityResource&gt; GetAllIdentityResources()
      {
          return _dbRepository.All&lt;IdentityResource&gt;();
      }
      private IEnumerable&lt;ApiResource&gt; GetAllApiResources()
      {
          return _dbRepository.All&lt;ApiResource&gt;();
      }
      private IEnumerable&lt;ApiScope&gt; GetAllApiScopes()
      {
          return _dbRepository.All&lt;ApiScope&gt;();
      }
  }
  </code></pre>
  <p><strong>Identity server setup</strong></p>
  <pre><code>services.Configure&lt;MongoDbConfigurationOptionsViewModel&gt;(Configuration);
          services.AddIdentityServer()//.AddProfileService&lt;ProfileService&gt;()
              .AddMongoRepository()
              .AddMongoDbForAspIdentity&lt;ApplicationUser, IdentityRole&gt;(Configuration)
              .AddClients()
              .AddInMemoryApiScopes(Config.AllowedScopes())
              .AddIdentityApiResources()
              .AddPersistedGrants()
              .AddDeveloperSigningCredential();
          
          services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
              .AddIdentityServerAuthentication(options =&gt;
              {
                  // base-address of your identityserver
                  options.Authority = &quot;https://localhost:5001&quot;;
  
                  // name of the API resource
                  options.ApiName = &quot;IdentityPortal.API&quot;;
              });
  </code></pre>
  <p><strong>Config</strong></p>
  <pre><code> public static IEnumerable&lt;ApiScope&gt; AllowedScopes()
          {
              return new List&lt;ApiScope&gt;
              {
                  new ApiScope(IdentityServerConstants.StandardScopes.OpenId),
                  new ApiScope(IdentityServerConstants.StandardScopes.Profile),
                  new ApiScope(IdentityServerConstants.StandardScopes.Email),
                  new ApiScope(apiScope)
              };
          }
  </code></pre>