Skip to content

Commit 3267e4a

Browse files
author
Thomas Duft
committed
chore: Update package references to their latest version and enabled ClientCredential Flow support in Sample server
1 parent bc661a9 commit 3267e4a

File tree

16 files changed

+135
-81
lines changed

16 files changed

+135
-81
lines changed

build/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public static async Task Main(string[] args)
101101
Run("dotnet", $"clean {solution} -c Release -v m --nologo");
102102
});
103103

104-
Target(Targets.Build, DependsOn(Targets.CleanBuildOutput), () =>
104+
Target(Targets.Build, dependsOn: [Targets.CleanBuildOutput], () =>
105105
{
106106
Run("dotnet", $"build {solution} -c Release --nologo");
107107
});
108108

109-
Target(Targets.Test, DependsOn(Targets.Build), () =>
109+
Target(Targets.Test, dependsOn: [Targets.Build], () =>
110110
{
111111
Run("dotnet", $"test {solution} -c Release --no-build --nologo");
112112
});
@@ -125,7 +125,7 @@ public static async Task Main(string[] args)
125125
Run("git", $"commit -am \"Committing changelog changes for v'{version}'\"");
126126
});
127127

128-
Target(Targets.Release, DependsOn(Targets.RestoreTools, Targets.Test, Targets.UpdateChangelog), () =>
128+
Target(Targets.Release, dependsOn: [Targets.RestoreTools, Targets.Test, Targets.UpdateChangelog], () =>
129129
{
130130
if (string.IsNullOrWhiteSpace(version))
131131
{
@@ -149,7 +149,7 @@ public static async Task Main(string[] args)
149149
}
150150
});
151151

152-
Target(Targets.Pack, DependsOn(Targets.Build, Targets.CleanPackOutput), () =>
152+
Target(Targets.Pack, dependsOn: [Targets.Build, Targets.CleanPackOutput], () =>
153153
{
154154
if (string.IsNullOrWhiteSpace(version))
155155
{
@@ -176,7 +176,7 @@ public static async Task Main(string[] args)
176176
}
177177
});
178178

179-
Target(Targets.Deploy, DependsOn(Targets.RestoreTools, Targets.Test, Targets.Pack), () =>
179+
Target(Targets.Deploy, dependsOn: [Targets.RestoreTools, Targets.Test, Targets.Pack], () =>
180180
{
181181
if (string.IsNullOrWhiteSpace(key))
182182
{

build/targets.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Bullseye" Version="5.0.0" />
9+
<PackageReference Include="Bullseye" Version="6.0.0" />
1010
<PackageReference Include="SimpleExec" Version="12.0.0" />
1111
</ItemGroup>
1212
</Project>

samples/Api/Api.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.3.1" />
10-
<PackageReference Include="OpenIddict.Validation.AspNetCore" Version="6.1.1" />
11-
<PackageReference Include="OpenIddict.Validation.SystemNetHttp" Version="6.1.1" />
9+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
10+
<PackageReference Include="OpenIddict.Validation.AspNetCore" Version="7.0.0" />
11+
<PackageReference Include="OpenIddict.Validation.SystemNetHttp" Version="7.0.0" />
1212
</ItemGroup>
1313

1414
</Project>

samples/Server/ConfigureServices.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ string environmentName
7474
});
7575
}
7676

77-
services.AddOpenIddict()
78-
// Register the OpenIddict core components.
77+
services.AddOpenIddict()
78+
// Register the OpenIddict core components.
7979
.AddCore(options =>
8080
{
8181
options.UseEntityFrameworkCore();
8282
if (!Helpers.Constants.IsTestingEnvironment(environmentName))
8383
{
8484
options.UseQuartz();
8585
}
86-
})
87-
// Register the OpenIddict server components.
86+
})
87+
// Register the OpenIddict server components.
8888
.AddServer(options =>
8989
{
9090
options.SetIssuer(new Uri("https://localhost:5001/"));
@@ -99,7 +99,8 @@ string environmentName
9999
// Note: this sample uses the code, device, password and refresh token flows, but you
100100
// can enable the other flows if you need to support implicit or client credentials.
101101
options.AllowAuthorizationCodeFlow()
102-
.AllowRefreshTokenFlow();
102+
.AllowRefreshTokenFlow()
103+
.AllowClientCredentialsFlow();
103104

104105
// Mark the "email", "profile", "roles" and "demo_api" scopes as supported scopes.
105106
options.RegisterScopes(
@@ -139,17 +140,17 @@ string environmentName
139140
{
140141
options.DisableAccessTokenEncryption();
141142
}
142-
})
143-
// Register the OpenIddict validation components.
143+
})
144+
// Register the OpenIddict validation components.
144145
.AddValidation(options =>
145146
{
146147
// Import the configuration from the local OpenIddict server instance.
147148
options.UseLocalServer();
148149

149150
// Register the ASP.NET Core host.
150151
options.UseAspNetCore();
151-
})
152-
// Register the EF based UI Store for OpenIddict related entities.
152+
})
153+
// Register the EF based UI Store for OpenIddict related entities.
153154
.AddUIStore(options =>
154155
{
155156
options.OpenIddictUIContext = builder =>
@@ -164,8 +165,8 @@ string environmentName
164165
.Name);
165166
});
166167
};
167-
})
168-
// Register the APIs for the EF based UI Store based on OpenIddict.
168+
})
169+
// Register the APIs for the EF based UI Store based on OpenIddict.
169170
.AddUIApis(options =>
170171
{
171172
// Tell the system about the allowed Permissions it is built/configured for.
@@ -178,15 +179,16 @@ string environmentName
178179
Permissions.GrantTypes.AuthorizationCode,
179180
Permissions.GrantTypes.DeviceCode,
180181
Permissions.GrantTypes.RefreshToken,
182+
Permissions.GrantTypes.ClientCredentials,
181183
Permissions.ResponseTypes.Code,
182184
Permissions.Scopes.Email,
183185
Permissions.Scopes.Profile,
184186
Permissions.Scopes.Roles,
185187
Permissions.Prefixes.Scope + "server_scope",
186188
Permissions.Prefixes.Scope + "api_scope"
187189
];
188-
})
189-
// Register the EF based UI Store for the ASP.NET Identity related entities.
190+
})
191+
// Register the EF based UI Store for the ASP.NET Identity related entities.
190192
.AddUIIdentityStore<ApplicationUser>(options =>
191193
{
192194
options.OpenIddictUIIdentityContext = builder =>
@@ -201,8 +203,8 @@ string environmentName
201203
.Name);
202204
});
203205
};
204-
})
205-
// Register the APIs for the EF based UI Store based on ASP.NET Identity.
206+
})
207+
// Register the APIs for the EF based UI Store based on ASP.NET Identity.
206208
.AddUIIdentityApis<ApplicationUser>();
207209

208210
if (!Helpers.Constants.IsTestingEnvironment(environmentName))

samples/Server/Controllers/AuthorizationController.cs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.AspNetCore.Identity;
66
using Microsoft.AspNetCore.Mvc;
77
using Microsoft.Extensions.Primitives;
8+
using Microsoft.IdentityModel.Tokens;
89
using OpenIddict.Abstractions;
910
using OpenIddict.Server.AspNetCore;
1011
using Server.Helpers;
@@ -370,7 +371,44 @@ public async Task<IActionResult> Exchange()
370371
return SignIn(principal, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
371372
}
372373

373-
else if (request.IsAuthorizationCodeGrantType() || request.IsDeviceCodeGrantType() || request.IsRefreshTokenGrantType())
374+
else if (request.IsClientCredentialsGrantType())
375+
{
376+
// Note: the client credentials are automatically validated by OpenIddict:
377+
// if client_id or client_secret are invalid, this action won't be invoked.
378+
379+
var application = await _applicationManager.FindByClientIdAsync(request.ClientId!)
380+
?? throw new InvalidOperationException("The application details cannot be found in the database.");
381+
382+
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
383+
var identity = new ClaimsIdentity(
384+
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
385+
nameType: Claims.Name,
386+
roleType: Claims.Role
387+
);
388+
389+
// Add the claims that will be persisted in the tokens (use the client_id as the subject identifier).
390+
identity.SetClaim(Claims.Subject, await _applicationManager.GetClientIdAsync(application));
391+
identity.SetClaim(Claims.Name, await _applicationManager.GetDisplayNameAsync(application));
392+
393+
// Note: In the original OAuth 2.0 specification, the client credentials grant
394+
// doesn't return an identity token, which is an OpenID Connect concept.
395+
//
396+
// As a non-standardized extension, OpenIddict allows returning an id_token
397+
// to convey information about the client application when the "openid" scope
398+
// is granted (i.e specified when calling principal.SetScopes()). When the "openid"
399+
// scope is not explicitly set, no identity token is returned to the client application.
400+
401+
// Set the list of scopes granted to the client application in access_token.
402+
identity.SetScopes(request.GetScopes());
403+
identity.SetResources(await _scopeManager.ListResourcesAsync(identity.GetScopes()).ToListAsync());
404+
identity.SetDestinations(GetDestinations);
405+
406+
return SignIn(new ClaimsPrincipal(identity), OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
407+
}
408+
409+
else if (request.IsAuthorizationCodeGrantType()
410+
|| request.IsDeviceCodeGrantType()
411+
|| request.IsRefreshTokenGrantType())
374412
{
375413
// Retrieve the claims principal stored in the authorization code/device code/refresh token.
376414
var principal = (await HttpContext.AuthenticateAsync(OpenIddictServerAspNetCoreDefaults.AuthenticationScheme)).Principal;
@@ -462,4 +500,18 @@ private static IEnumerable<string> GetDestinations(Claim claim, ClaimsPrincipal
462500
yield break;
463501
}
464502
}
503+
504+
private static IEnumerable<string> GetDestinations(Claim claim)
505+
{
506+
// Note: by default, claims are NOT automatically included in the access and identity tokens.
507+
// To allow OpenIddict to serialize them, you must attach them a destination, that specifies
508+
// whether they should be included in access tokens, in identity tokens or in both.
509+
510+
return claim.Type switch
511+
{
512+
Claims.Name or Claims.Subject => [Destinations.AccessToken, Destinations.IdentityToken],
513+
514+
_ => [Destinations.AccessToken],
515+
};
516+
}
465517
}

samples/Server/Server.csproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.2" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.8" />
1414
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
15-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.2" />
15+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.8" />
1616

17-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.2" />
18-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
17+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.8" />
18+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.8">
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
2222

23-
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.13.1" />
23+
<PackageReference Include="Quartz.Extensions.Hosting" Version="3.15.0" />
2424

25-
<PackageReference Include="OpenIddict.AspNetCore" Version="6.1.1" />
26-
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="6.1.1" />
27-
<PackageReference Include="OpenIddict.Quartz" Version="6.1.1" />
25+
<PackageReference Include="OpenIddict.AspNetCore" Version="7.0.0" />
26+
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="7.0.0" />
27+
<PackageReference Include="OpenIddict.Quartz" Version="7.0.0" />
2828

2929
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
3030
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
3131
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
3232
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
33-
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.3.1" />
33+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.3" />
3434
</ItemGroup>
3535

3636
<ItemGroup>

samples/Server/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"ConnectionStrings": {
33
"DefaultConnection": "Filename=server.sqlite"
44
},
5-
"DisableAccessTokenEncryption": false,
5+
"DisableAccessTokenEncryption": true,
66
"Serilog": {
77
"MinimumLevel": {
88
"Default": "Information",

src/identity/OpenIddict.UI.Identity.Api/tomware.OpenIddict.UI.Identity.Api.csproj

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.3.0" />
13-
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="9.0.2" />
14-
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.2" />
15-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
16-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.2" />
17-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
18-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
19-
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.2" />
20-
<PackageReference Include="OpenIddict.AspNetCore" Version="6.1.1" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.3.1" />
13+
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="9.0.8" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.8" />
15+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
16+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.8" />
17+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.8" />
18+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
19+
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.8" />
20+
<PackageReference Include="OpenIddict.AspNetCore" Version="7.0.0" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

src/identity/OpenIddict.UI.Identity.Core/tomware.OpenIddict.UI.Identity.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
13-
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.2" />
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
13+
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="9.0.8" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

src/identity/OpenIddict.UI.Identity.Infrastructure/tomware.OpenIddict.UI.Identity.Infrastructure.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.2" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
14-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
15-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.2" />
16-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.2" />
17-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
18-
<PackageReference Include="OpenIddict.Abstractions" Version="6.1.1" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="9.0.8" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.8" />
14+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.8" />
15+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.8" />
16+
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.8" />
17+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.8" />
18+
<PackageReference Include="OpenIddict.Abstractions" Version="7.0.0" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

0 commit comments

Comments
 (0)