Getting started
-To use OpenIddict, you need to:
+To implement a custom OpenID Connect server using OpenIddict, the simplest option is to clone one of the official samples from the openiddict-samples repository.
+If you don't want to start from one of the recommended samples, you'll need to:
-
-
Install the latest .NET Core 2.x tooling and update your packages to reference the ASP.NET Core 2.x packages.
+Install the .NET Core 2.1.x, 3.1.x or .NET 5.0.x tooling.
-Have an existing project or create a new one: when creating a new project using Visual Studio's default ASP.NET Core template, using individual user accounts authentication is strongly recommended. When updating an existing project, you must provide your own
+AccountController
to handle the registration process and the authentication flow.Have an existing project or create a new one: when creating a new project using Visual Studio's default ASP.NET Core template, +using individual user accounts authentication is strongly recommended as it automatically includes the default ASP.NET Core Identity UI, based on Razor Pages.
Update your
-.csproj
file to reference theOpenIddict
packages:<PackageReference Include="OpenIddict" Version="2.0.0-*" /> -<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="2.0.0-*" /> +
<PackageReference Include="OpenIddict.AspNetCore" Version="3.0.0" /> +<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.0.0" />
-OPTIONAL: If you want to try out the latest features and bug fixes, there is a MyGet feed with nightly builds -of OpenIddict.
-To reference the OpenIddict MyGet feed, create a
-NuGet.config
file (at the root of your solution):<?xml version="1.0" encoding="utf-8"?> -<configuration> - <packageSources> - <add key="nuget" value="https://api.nuget.org/v3/index.json" /> - <add key="openiddict" value="https://www.myget.org/F/openiddict/api/v3/index.json" /> - </packageSources> -</configuration> -
-Configure the OpenIddict services in
+Startup.ConfigureServices
:Configure the OpenIddict core, server and validation services in
Startup.ConfigureServices
. +Here's an example for the client credentials grant, used in machine-to-machine scenarios:public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddControllersWithViews(); services.AddDbContext<ApplicationDbContext>(options => { // Configure the context to use Microsoft SQL Server. - options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]); + options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")); // Register the entity sets needed by OpenIddict. // Note: use the generic overload if you need @@ -105,56 +97,74 @@ of OpenIddict.