("OpenIddict:EnableAdminApi"))
+{
+ app.MapOpenIddictAdminApi(Policies.Admin);
+}
+
+app.Run();
diff --git a/templates/content/OpenIddict.Server.Identity/Properties/launchSettings.json b/templates/content/OpenIddict.Server.Identity/Properties/launchSettings.json
new file mode 100644
index 00000000..fc03871a
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Properties/launchSettings.json
@@ -0,0 +1,13 @@
+{
+ "$schema": "https://json.schemastore.org/launchsettings.json",
+ "profiles": {
+ "https": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "applicationUrl": "https://localhost:44310;http://localhost:5010",
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ }
+ }
+ }
+}
diff --git a/templates/content/OpenIddict.Server.Identity/ViewModels/AuthorizeViewModel.cs b/templates/content/OpenIddict.Server.Identity/ViewModels/AuthorizeViewModel.cs
new file mode 100644
index 00000000..8f580ec0
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/ViewModels/AuthorizeViewModel.cs
@@ -0,0 +1,12 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace Company.Server.ViewModels;
+
+public class AuthorizeViewModel
+{
+ [Display(Name = "Application")]
+ public string? ApplicationName { get; set; }
+
+ [Display(Name = "Scope")]
+ public string? Scope { get; set; }
+}
diff --git a/templates/content/OpenIddict.Server.Identity/ViewModels/VerifyViewModel.cs b/templates/content/OpenIddict.Server.Identity/ViewModels/VerifyViewModel.cs
new file mode 100644
index 00000000..7a39e973
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/ViewModels/VerifyViewModel.cs
@@ -0,0 +1,25 @@
+using System.ComponentModel.DataAnnotations;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.ModelBinding;
+using OpenIddict.Abstractions;
+
+namespace Company.Server.ViewModels;
+
+public class VerifyViewModel
+{
+ [Display(Name = "Application")]
+ public string? ApplicationName { get; set; }
+
+ [BindNever, Display(Name = "Error")]
+ public string? Error { get; set; }
+
+ [BindNever, Display(Name = "Error description")]
+ public string? ErrorDescription { get; set; }
+
+ [Display(Name = "Scope")]
+ public string? Scope { get; set; }
+
+ [FromQuery(Name = OpenIddictConstants.Parameters.UserCode)]
+ [Display(Name = "User code")]
+ public string? UserCode { get; set; }
+}
diff --git a/templates/content/OpenIddict.Server.Identity/Views/Authorization/Authorize.cshtml b/templates/content/OpenIddict.Server.Identity/Views/Authorization/Authorize.cshtml
new file mode 100644
index 00000000..1a85e3d2
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/Authorization/Authorize.cshtml
@@ -0,0 +1,21 @@
+@using Microsoft.Extensions.Primitives
+@model AuthorizeViewModel
+@{
+ ViewData["Title"] = "Authorization";
+}
+
+Authorization
+
+Do you want to grant @Model.ApplicationName access to your data? (scopes requested: @Model.Scope)
+
+
diff --git a/templates/content/OpenIddict.Server.Identity/Views/Authorization/EndSession.cshtml b/templates/content/OpenIddict.Server.Identity/Views/Authorization/EndSession.cshtml
new file mode 100644
index 00000000..4f16764f
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/Authorization/EndSession.cshtml
@@ -0,0 +1,19 @@
+@using Microsoft.Extensions.Primitives
+@{
+ ViewData["Title"] = "Log out";
+}
+
+Log out
+
+Are you sure you want to sign out?
+
+
diff --git a/templates/content/OpenIddict.Server.Identity/Views/Authorization/Verify.cshtml b/templates/content/OpenIddict.Server.Identity/Views/Authorization/Verify.cshtml
new file mode 100644
index 00000000..6e48c5a5
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/Authorization/Verify.cshtml
@@ -0,0 +1,50 @@
+@using Microsoft.Extensions.Primitives
+@model VerifyViewModel
+@{
+ ViewData["Title"] = "Device authorization";
+}
+
+Authorization
+
+@if (string.IsNullOrEmpty(Model.UserCode) || !string.IsNullOrEmpty(Model.Error))
+{
+ @if (!string.IsNullOrEmpty(Model.Error) && !string.IsNullOrEmpty(Model.ErrorDescription))
+ {
+
+ An error occurred:
+
+ @Model.ErrorDescription (@Model.Error)
+
+ }
+
+ Enter the user code given by the client application:
+
+
+}
+else
+{
+ Do you want to grant @Model.ApplicationName access to your data? (scopes requested: @Model.Scope)
+
+ Make sure that the code displayed on the device is @Model.UserCode .
+
+ If the two codes don't match, press "No" to reject the authorization demand.
+
+
+
+}
diff --git a/templates/content/OpenIddict.Server.Identity/Views/Shared/_Layout.cshtml b/templates/content/OpenIddict.Server.Identity/Views/Shared/_Layout.cshtml
new file mode 100644
index 00000000..de3246e6
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/Shared/_Layout.cshtml
@@ -0,0 +1,23 @@
+
+
+
+
+
+ @ViewData["Title"] - Company.Server
+
+
+
+
+
+
+
+
+ @RenderBody()
+
+
+ @await RenderSectionAsync("Scripts", required: false)
+
+
diff --git a/templates/content/OpenIddict.Server.Identity/Views/Shared/_LoginPartial.cshtml b/templates/content/OpenIddict.Server.Identity/Views/Shared/_LoginPartial.cshtml
new file mode 100644
index 00000000..a2519800
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/Shared/_LoginPartial.cshtml
@@ -0,0 +1,17 @@
+@* Note: this partial view is also used by the default ASP.NET Core Identity UI layout. *@
+
diff --git a/templates/content/OpenIddict.Server.Identity/Views/_ViewImports.cshtml b/templates/content/OpenIddict.Server.Identity/Views/_ViewImports.cshtml
new file mode 100644
index 00000000..ca772368
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/_ViewImports.cshtml
@@ -0,0 +1,3 @@
+@using Company.Server
+@using Company.Server.ViewModels
+@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
diff --git a/templates/content/OpenIddict.Server.Identity/Views/_ViewStart.cshtml b/templates/content/OpenIddict.Server.Identity/Views/_ViewStart.cshtml
new file mode 100644
index 00000000..820a2f6e
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Views/_ViewStart.cshtml
@@ -0,0 +1,3 @@
+@{
+ Layout = "_Layout";
+}
diff --git a/templates/content/OpenIddict.Server.Identity/Worker.cs b/templates/content/OpenIddict.Server.Identity/Worker.cs
new file mode 100644
index 00000000..94898ca7
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/Worker.cs
@@ -0,0 +1,34 @@
+using Company.Server.Data;
+using OpenIddict.Abstractions;
+
+namespace Company.Server;
+
+///
+/// Creates the database and registers the client applications declared in the "OpenIddict:Clients" section.
+///
+/// In production, the database should be created using migrations as part of the deployment.
+public class Worker(IServiceProvider provider, IConfiguration configuration) : IHostedService
+{
+ public async Task StartAsync(CancellationToken cancellationToken)
+ {
+ await using var scope = provider.CreateAsyncScope();
+
+ var context = scope.ServiceProvider.GetRequiredService();
+ await context.Database.EnsureCreatedAsync(cancellationToken);
+
+ var manager = scope.ServiceProvider.GetRequiredService();
+
+ foreach (var client in configuration.GetSection("OpenIddict:Clients").Get>() ?? [])
+ {
+ if (string.IsNullOrEmpty(client.ClientId) ||
+ await manager.FindByClientIdAsync(client.ClientId, cancellationToken) is not null)
+ {
+ continue;
+ }
+
+ await manager.CreateAsync(client.CreateDescriptor(), cancellationToken);
+ }
+ }
+
+ public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+}
diff --git a/templates/content/OpenIddict.Server.Identity/appsettings.Development.json b/templates/content/OpenIddict.Server.Identity/appsettings.Development.json
new file mode 100644
index 00000000..3e5fb25c
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/appsettings.Development.json
@@ -0,0 +1,14 @@
+{
+ "OpenIddict": {
+ "Clients": [
+ {
+ "ClientId": "oidc-debugger",
+ "DisplayName": "OpenID Connect debugger",
+ "ConsentType": "explicit",
+ "GrantTypes": [ "authorization_code", "refresh_token" ],
+ "Scopes": [ "openid", "email", "profile", "roles", "offline_access" ],
+ "RedirectUris": [ "https://oidcdebugger.com/debug" ]
+ }
+ ]
+ }
+}
diff --git a/templates/content/OpenIddict.Server.Identity/appsettings.json b/templates/content/OpenIddict.Server.Identity/appsettings.json
new file mode 100644
index 00000000..329bcb6b
--- /dev/null
+++ b/templates/content/OpenIddict.Server.Identity/appsettings.json
@@ -0,0 +1,17 @@
+{
+ "ConnectionStrings": {
+ "DefaultConnection": "Data Source=Company.Server.sqlite3"
+ },
+ "OpenIddict": {
+ "EnableAdminApi": false,
+ "AdminRole": "admin",
+ "Clients": []
+ },
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ },
+ "AllowedHosts": "*"
+}
diff --git a/templates/verify.sh b/templates/verify.sh
new file mode 100644
index 00000000..e96a6ec3
--- /dev/null
+++ b/templates/verify.sh
@@ -0,0 +1,135 @@
+#!/usr/bin/env bash
+# Packs the OpenIddict packages used by the templates into a temporary feed, instantiates
+# each template, builds the generated projects and runs HTTP smoke tests against them.
+#
+# Requirements: bash, curl, openssl, python and a trusted ASP.NET Core development certificate.
+# Usage: templates/verify.sh [work directory]
+set -u
+
+REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+WORK="${1:-$(mktemp -d)}"
+mkdir -p "$WORK/feed" "$WORK/home" "$WORK/packages" "$WORK/out"
+
+if [ -x "$REPO/.dotnet/dotnet" ] || [ -x "$REPO/.dotnet/dotnet.exe" ]; then
+ export DOTNET_ROOT="$REPO/.dotnet"
+ DN="$REPO/.dotnet/dotnet"
+else
+ DN="dotnet"
+fi
+
+export DOTNET_CLI_HOME="$WORK/home"
+export NUGET_PACKAGES="$WORK/packages"
+export DOTNET_NOLOGO=1
+export ASPNETCORE_ENVIRONMENT=Development
+
+FAILURES=0
+
+check() { # name expected actual
+ if [ "$2" == "$3" ]; then echo " PASS $1"; else echo " FAIL $1: expected $2, got $3"; FAILURES=$((FAILURES + 1)); fi
+}
+
+echo "== pack"
+for p in OpenIddict.Abstractions OpenIddict.Core OpenIddict.Server OpenIddict.Server.AspNetCore \
+ OpenIddict.EntityFrameworkCore.Models OpenIddict.EntityFrameworkCore OpenIddict.Client \
+ OpenIddict.Client.AspNetCore OpenIddict.Client.SystemNetHttp OpenIddict.Client.AspNetCore.Bff; do
+ "$DN" pack "$REPO/src/$p/$p.csproj" -o "$WORK/feed" > "$WORK/out/pack-$p.log" 2>&1 || { echo " FAIL pack $p (see $WORK/out/pack-$p.log)"; exit 1; }
+done
+
+VERSION="$(ls "$WORK/feed" | sed -n 's/^OpenIddict\.Abstractions\.\(.*\)\.nupkg$/\1/p' | head -1)"
+echo " version $VERSION"
+
+cat > "$WORK/nuget.config" <
+
+
+
+
+
+
+
+EOF
+
+cd "$WORK"
+
+echo "== instantiate and build"
+for t in Server.Identity:openiddict-server-identity:IdentityServer Server.Empty:openiddict-server-empty:EmptyServer Bff:openiddict-bff:BffHost; do
+ IFS=: read -r folder name project <<< "$t"
+ "$DN" new install "$REPO/templates/content/OpenIddict.$folder" > /dev/null 2>&1 || { echo " FAIL install $name"; exit 1; }
+ rm -rf "$project"
+ "$DN" new "$name" -n "$project" --OpenIddictVersion "$VERSION" > /dev/null || { echo " FAIL new $name"; exit 1; }
+ if "$DN" build "$project/$project.csproj" > "$WORK/out/build-$project.log" 2>&1; then echo " PASS build $name"; else echo " FAIL build $name (see $WORK/out/build-$project.log)"; exit 1; fi
+done
+
+start() { # project port
+ rm -f "$1"/*.sqlite3*
+ (cd "$1" && "$DN" "bin/Debug/net10.0/$1.dll" --urls "https://127.0.0.1:$2" > "$WORK/out/run-$1.log" 2>&1 &)
+ for _ in $(seq 1 60); do curl -sk -o /dev/null "https://127.0.0.1:$2/" && return; sleep 1; done
+}
+
+stop() { # port
+ if command -v taskkill > /dev/null; then
+ for pid in $(netstat -ano | grep "127.0.0.1:$1 .*LISTENING" | awk '{print $5}' | sort -u); do taskkill //F //PID "$pid" > /dev/null; done
+ else
+ fuser -k "$1/tcp" > /dev/null 2>&1
+ fi
+ sleep 1
+}
+
+status() { curl -sk -o /dev/null -w '%{http_code}' "$@"; }
+
+VERIFIER="dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXkdBjftJeZ4CVP"
+CHALLENGE=$(printf '%s' "$VERIFIER" | openssl dgst -sha256 -binary | base64 | tr '+/' '-_' | tr -d '=')
+QUERY="client_id=oidc-debugger&response_type=code&redirect_uri=https%3A%2F%2Foidcdebugger.com%2Fdebug&scope=openid%20profile%20email&code_challenge=$CHALLENGE&code_challenge_method=S256"
+json() { python -c "import json,sys;print(json.dumps(json.load(sys.stdin).get('$1')))"; }
+redeem() { # base
+ curl -sk --data-urlencode "grant_type=authorization_code" --data-urlencode "client_id=oidc-debugger" --data-urlencode "code=$CODE" \
+ --data-urlencode "code_verifier=$VERIFIER" --data-urlencode "redirect_uri=https://oidcdebugger.com/debug" "$1/connect/token" |
+ python -c "import json,sys;print(json.load(sys.stdin).get('access_token',''))"
+}
+
+echo "== smoke openiddict-server-identity"
+start IdentityServer 5198
+B=https://127.0.0.1:5198; J="$WORK/identity.cookies"; rm -f "$J"
+check discovery 200 "$(status "$B/.well-known/openid-configuration")"
+check admin-api-disabled 404 "$(status "$B/openiddict/admin/applications")"
+TOKEN=$(curl -sk -c "$J" -b "$J" "$B/Identity/Account/Register" | grep -o 'name="__RequestVerificationToken" type="hidden" value="[^"]*"' | head -1 | sed 's/.*value="//;s/"$//')
+check register 302 "$(status -c "$J" -b "$J" --data-urlencode "__RequestVerificationToken=$TOKEN" --data-urlencode "Input.Email=alice@example.com" \
+ --data-urlencode "Input.Password=Passw0rd!Passw0rd" --data-urlencode "Input.ConfirmPassword=Passw0rd!Passw0rd" "$B/Identity/Account/Register")"
+PAGE=$(curl -sk -c "$J" -b "$J" "$B/connect/authorize?$QUERY")
+TOKEN=$(printf '%s' "$PAGE" | grep -o 'name="__RequestVerificationToken" type="hidden" value="[^"]*"' | head -1 | sed 's/.*value="//;s/"$//')
+check consent-form yes "$([ -n "$TOKEN" ] && echo yes || echo no)"
+LOCATION=$(curl -sk -c "$J" -b "$J" -o /dev/null -w '%{redirect_url}' --data "$QUERY" --data-urlencode "__RequestVerificationToken=$TOKEN" --data-urlencode "submit.Accept=Yes" "$B/connect/authorize")
+CODE=$(printf '%s' "$LOCATION" | grep -o 'code=[^&]*' | head -1 | cut -d= -f2)
+check authorization-code yes "$([ -n "$CODE" ] && echo yes || echo no)"
+ACCESS=$(redeem "$B")
+check userinfo '"alice@example.com"' "$(curl -sk -H "Authorization: Bearer $ACCESS" "$B/connect/userinfo" | json email)"
+stop 5198
+
+echo "== smoke openiddict-server-empty"
+start EmptyServer 5197
+B=https://127.0.0.1:5197; J="$WORK/empty.cookies"; rm -f "$J"
+AUTHZ="/connect/authorize?$QUERY"
+check discovery 200 "$(status "$B/.well-known/openid-configuration")"
+check authorize-challenge 302 "$(status -c "$J" -b "$J" "$B$AUTHZ")"
+TOKEN=$(curl -sk -c "$J" -b "$J" "$B/account/login" | grep -o 'name="__RequestVerificationToken" value="[^"]*"' | sed 's/.*value="//;s/"$//')
+check login 302 "$(status -c "$J" -b "$J" --data-urlencode "__RequestVerificationToken=$TOKEN" --data-urlencode "UserName=alice" --data-urlencode "ReturnUrl=$AUTHZ" "$B/account/login")"
+LOCATION=$(curl -sk -c "$J" -b "$J" -o /dev/null -w '%{redirect_url}' "$B$AUTHZ")
+CODE=$(printf '%s' "$LOCATION" | grep -o 'code=[^&]*' | head -1 | cut -d= -f2)
+check authorization-code yes "$([ -n "$CODE" ] && echo yes || echo no)"
+ACCESS=$(redeem "$B")
+check userinfo '"alice"' "$(curl -sk -H "Authorization: Bearer $ACCESS" "$B/connect/userinfo" | json sub)"
+stop 5197
+
+echo "== smoke openiddict-bff"
+start BffHost 5196
+B=https://127.0.0.1:5196
+check index 200 "$(status "$B/")"
+check user-anonymous 401 "$(status -H 'X-CSRF: 1' "$B/bff/user")"
+check api-without-antiforgery-header 401 "$(status "$B/api/me")"
+check api-anonymous 401 "$(status -H 'X-CSRF: 1' "$B/api/me")"
+stop 5196
+
+for t in Server.Identity Server.Empty Bff; do "$DN" new uninstall "$REPO/templates/content/OpenIddict.$t" > /dev/null 2>&1; done
+
+echo "== $FAILURES failure(s)"
+exit "$FAILURES"