Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
OpenIddict Startup Example (with postgres and custom password rules)
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace MyApp.Api
public class Startup
public IConfigurationRoot Configuration { get; }
public Startup(IHostingEnvironment env)
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
Configuration = builder.Build();
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
services.AddCors(); // <- ADD THIS
.AddDbContext<ApplicationDbContext>(options =>
services.AddIdentity<ApplicationUser, IdentityRole>(o => {
o.Password.RequireDigit = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequiredLength = 6;
.AddOpenIddict(); // <- ADD THIS
services.AddSingleton<IContextFactory, ContextFactory>();
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
app.UseCors(builder => // <- ADD THIS
app.UseOAuthValidation(); // <- ADD THIS
app.UseOpenIddict(); // <- ADD THIS

This comment has been minimized.

Copy link

hegelstad commented Feb 16, 2017


  • What is added exactly to use Sqlite for development.
  • Why does the tutorial differ from the offical one on OpenIddict github pages.
  • What does ApplicationDbContext look like, is it unchanged?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.