How to add new Scope in ClientScopes table using IdentityServer4 with Entity Framework Core

c# entity-framework-core identityserver4 openid-connect


I have configured IdentityServer4 for an authentication with Entity Framework Core in my application and have also added a few clients. I tried to add a new scope for any client in ClientScopes table. I was not able to add it from code level and also ClientScopes table does not exist in ConfigurationDbContext.

using System;
using System.Threading.Tasks;
using IdentityServer4.EntityFramework.Entities;
using IdentityServer4.EntityFramework.Interfaces;
using IdentityServer4.EntityFramework.Options;
using Microsoft.EntityFrameworkCore;

namespace IdentityServer4.EntityFramework.DbContexts
    public class ConfigurationDbContext : DbContext, IConfigurationDbContext, IDisposable
        public ConfigurationDbContext(DbContextOptions<ConfigurationDbContext> options, ConfigurationStoreOptions storeOptions);

        public DbSet<ApiResource> ApiResources { get; set; }
        public DbSet<Client> Clients { get; set; }
        public DbSet<IdentityResource> IdentityResources { get; set; }

        public Task<int> SaveChangesAsync();
        protected override void OnModelCreating(ModelBuilder modelBuilder);

Can anyone please guide me how can I add a new scope to the existing clients?

1/26/2018 7:17:26 PM

Popular Answer

I suppose that you are using one of the quick starts? Am I right? If so - then you are using the InMemory ApiResources. They are configured in the Startup.cs:

 public void ConfigureServices(IServiceCollection services)
        // configure identity server with in-memory stores, keys, clients and scopes

Go to this Config.GetApiResources() (it is in Config.cs file) and there you can add the scopes that you need. Of course in your clients table, you should also add the scope to the allowed scopes for the client.

1/26/2018 6:17:03 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow