question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot move OpenIddict entities to custom schema after new version

See original GitHub issue

Hi, I have been putting the OpenIddict entities in their own “OpenIddict” schema in my database. It has worked fine until the latest version.

Right now, it is creating the tables in the “OpenIddict” schema like I want it to, but it is also creating the default schema (public as I’m using PGSQL) as well.

Any suggestions? I’m sure I’m just missing something in my Startup.cs.

Thanks!

image

image

In my Startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            ....
            services.AddEntityFrameworkNpgsql().AddDbContextPool<AppDbContext>(options =>
            {
                options.UseNpgsql(Configuration["pgsql:housestay"], b => b.MigrationsAssembly("HouseStayEF"));
                options.UseOpenIddict();
            });
            ....
            services.AddOpenIddict()
                .AddCore(options =>
                {
                    options.UseEntityFrameworkCore().UseDbContext<AppDbContext>();
                })
                .AddServer(options =>
                {
                    options.UseMvc();
                    options.EnableTokenEndpoint("/auth/token");

                    options.AllowPasswordFlow();
                    //options.AllowCustomFlow(GrantTypes.Facebook);
                    //options.AllowCustomFlow(GrantTypes.Google);
                    options.AllowRefreshTokenFlow();

                    //options.AcceptAnonymousClients();

                    options.RegisterScopes(
                        OpenIdConnectConstants.Scopes.Email,
                        OpenIdConnectConstants.Scopes.Profile,
                        OpenIddictConstants.Scopes.Roles
                        );

                    options.SetAccessTokenLifetime(TimeSpan.FromHours(1));
                    options.SetRefreshTokenLifetime(TimeSpan.FromDays(180));

                    if (!_isProduction)
                    {
                        options.DisableHttpsRequirement();
                    }
                });
            ....
        }

In my AppDbContext.OnModelCreating:

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        .....
        builder.Entity<OpenIddictApplication>(e => { e.ToTable("Applications", "OpenIddict"); });

        builder.Entity<OpenIddictAuthorization>(e => { e.ToTable("Authorizations", "OpenIddict"); });

        builder.Entity<OpenIddictScope>(e => { e.ToTable("Scopes", "OpenIddict"); });

        builder.Entity<OpenIddictToken>(e => { e.ToTable("Tokens", "OpenIddict"); });
        .....
    }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kevinchaletcommented, Jul 4, 2018

You can use the ASP.NET Core authorization policy builder: policy.RequireClaim(OAuthValidationConstants.Claims.Scope, "marketing_api").

1reaction
ArcadeRenegadecommented, Jul 4, 2018

Sorry, I missed that announcement. I removed the deprecated package and updated my DbContext OnModelCreating to use the models from OpenIddict.EntityFrameworkCore.Models instead.

Works as expected now. Thanks for your help. OpenIddict has been very useful!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to force creation of OpenIddict tables in not empty DB
The only way is to create own Stores and StoreResolvers for OpenIddict and migrate tables creation to any suitable solution: a set of...
Read more >
modules/openiddict | Documentation Center | ABP.IO
The OpenIddict module adds the following items to the "Main" menu, under the "Administration" menu item: Applications: Application management page. Scopes: ...
Read more >
Migrate to OpenIddict 3.0
Migrating to OpenIddict 3.0 requires making changes to your database: existing properties have been reworked and new ones have been added to support...
Read more >
Getting started - OpenIddict documentation
To implement a custom OpenID Connect server using OpenIddict, the simplest option is to clone one of the official samples from the openiddict-samples ......
Read more >
Introducing OpenIddict 3.0 beta1 | Kévin Chalet's blog
In this post, discover the major changes introduced in OpenIddict 3.0.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found