Skip to content

Commit 9e475db

Browse files
Update the OpenIddict Saml idp sample.
1 parent 2204494 commit 9e475db

File tree

5 files changed

+25
-26
lines changed

5 files changed

+25
-26
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ ClientBin/
197197
*.dbmdl
198198
*.dbproj.schemaview
199199
*.jfm
200-
*.pfx
201200
*.publishsettings
202201
orleans.codegen.cs
203202

OpenIddict/OpenIddictIdP/Controllers/AuthorizationController.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public async Task<IActionResult> Authorize()
6262
// - If prompt=login was specified by the client application.
6363
// - If a max_age parameter was provided and the authentication cookie is not considered "fresh" enough.
6464
var result = await HttpContext.AuthenticateAsync(IdentityConstants.ApplicationScheme);
65-
if (result == null || !result.Succeeded || request.HasPrompt(Prompts.Login) ||
65+
if (result == null || !result.Succeeded || request.HasPromptValue(PromptValues.Login) ||
6666
request.MaxAge != null && result.Properties?.IssuedUtc != null &&
6767
DateTimeOffset.UtcNow - result.Properties.IssuedUtc > TimeSpan.FromSeconds(request.MaxAge.Value))
6868
{
6969
// If the client application requested promptless authentication,
7070
// return an error indicating that the user is not logged in.
71-
if (request.HasPrompt(Prompts.None))
71+
if (request.HasPromptValue(PromptValues.None))
7272
{
7373
return Forbid(
7474
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
@@ -81,7 +81,7 @@ public async Task<IActionResult> Authorize()
8181

8282
// To avoid endless login -> authorization redirects, the prompt=login flag
8383
// is removed from the authorization request payload before redirecting the user.
84-
var prompt = string.Join(" ", request.GetPrompts().Remove(Prompts.Login));
84+
var prompt = string.Join(" ", request.GetPromptValues().Remove(PromptValues.Login));
8585

8686
var parameters = Request.HasFormContentType ?
8787
Request.Form.Where(parameter => parameter.Key != Parameters.Prompt).ToList() :
@@ -142,7 +142,7 @@ public async Task<IActionResult> Authorize()
142142
// return an authorization response without displaying the consent form.
143143
case ConsentTypes.Implicit:
144144
case ConsentTypes.External when authorizations.Any():
145-
case ConsentTypes.Explicit when authorizations.Any() && !request.HasPrompt(Prompts.Consent):
145+
case ConsentTypes.Explicit when authorizations.Any() && !request.HasPromptValue(PromptValues.Consent):
146146
// Create the claims-based identity that will be used by OpenIddict to generate tokens.
147147
var identity = new ClaimsIdentity(
148148
authenticationType: TokenValidationParameters.DefaultAuthenticationType,
@@ -178,8 +178,8 @@ public async Task<IActionResult> Authorize()
178178

179179
// At this point, no authorization was found in the database and an error must be returned
180180
// if the client application specified prompt=none in the authorization request.
181-
case ConsentTypes.Explicit when request.HasPrompt(Prompts.None):
182-
case ConsentTypes.Systematic when request.HasPrompt(Prompts.None):
181+
case ConsentTypes.Explicit when request.HasPromptValue(PromptValues.None):
182+
case ConsentTypes.Systematic when request.HasPromptValue(PromptValues.None):
183183
return Forbid(
184184
authenticationSchemes: OpenIddictServerAspNetCoreDefaults.AuthenticationScheme,
185185
properties: new AuthenticationProperties(new Dictionary<string, string>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace openiddictidp;
2+
3+
public class JwtClaimTypes
4+
{
5+
public const string Subject = "sub";
6+
public const string Name = "name";
7+
public const string Role = "role";
8+
public const string Email = "email";
9+
}

OpenIddict/OpenIddictIdP/Startup.cs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Rsk.Saml.OpenIddict.Quartz.Configuration.DependencyInjection;
2-
using IdentityModel;
32
using Microsoft.AspNetCore.Builder;
43
using Microsoft.AspNetCore.Hosting;
54
using Microsoft.AspNetCore.Identity;
@@ -15,6 +14,7 @@
1514
using Rsk.Saml.OpenIddict.EntityFrameworkCore.Configuration.DependencyInjection;
1615
using Rsk.Saml.Samples;
1716
using static OpenIddict.Abstractions.OpenIddictConstants;
17+
using Microsoft.Extensions.Options;
1818

1919
namespace openiddictidp;
2020

@@ -92,9 +92,9 @@ public void ConfigureServices(IServiceCollection services)
9292

9393
// Enable the authorization, logout, token and userinfo endpoints.
9494
options.SetAuthorizationEndpointUris("connect/authorize")
95-
.SetLogoutEndpointUris("connect/logout")
95+
.SetEndSessionEndpointUris("connect/logout")
9696
.SetTokenEndpointUris("connect/token")
97-
.SetUserinfoEndpointUris("connect/userinfo");
97+
.SetUserInfoEndpointUris("connect/userinfo");
9898

9999
// Mark the "email", "profile" and "roles" scopes as supported scopes.
100100
options.RegisterScopes(Scopes.Email, Scopes.Profile, Scopes.Roles);
@@ -110,9 +110,9 @@ public void ConfigureServices(IServiceCollection services)
110110
// Register the ASP.NET Core host and configure the ASP.NET Core-specific options.
111111
options.UseAspNetCore()
112112
.EnableAuthorizationEndpointPassthrough()
113-
.EnableLogoutEndpointPassthrough()
113+
.EnableEndSessionEndpointPassthrough()
114114
.EnableTokenEndpointPassthrough()
115-
.EnableUserinfoEndpointPassthrough()
115+
.EnableUserInfoEndpointPassthrough()
116116
.EnableStatusCodePagesIntegration();
117117

118118
options.AddSamlPlugin(builder =>
@@ -122,18 +122,9 @@ public void ConfigureServices(IServiceCollection services)
122122

123123
//Already added the DbContext above
124124
builder.UseSamlEntityFrameworkCore()
125-
.AddSamlMessageDbContext(optionsBuilder =>
126-
{
127-
//Configure the database provider to use.
128-
optionsBuilder.UseSqlServer(defaultConnectionString, x =>x.MigrationsAssembly(typeof(Startup).Assembly.FullName));
129-
})
130-
.AddSamlConfigurationDbContext(optionsBuilder =>
131-
{
132-
//Configure the database provider to use.
133-
optionsBuilder.UseSqlServer(defaultConnectionString,
134-
x => x.MigrationsAssembly(typeof(Startup).Assembly.FullName));
135-
});
136-
125+
.AddSamlDbContexts(optionsBuilder => optionsBuilder.UseSqlServer(defaultConnectionString,
126+
x => x.MigrationsAssembly(typeof(Startup).Assembly.FullName)));
127+
137128
builder.ConfigureSamlOpenIddictServerOptions(serverOptions =>
138129
{
139130
serverOptions.HostOptions = new SamlHostUserInteractionOptions()
@@ -202,4 +193,4 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
202193
endpoints.MapRazorPages();
203194
});
204195
}
205-
}
196+
}

OpenIddict/OpenIddictIdP/Worker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private Task CreateMvcClientIfNotExists(IServiceScope scope)
154154
ocd.Permissions.UnionWith(new[]
155155
{
156156
Permissions.Endpoints.Authorization,
157-
Permissions.Endpoints.Logout,
157+
Permissions.Endpoints.EndSession,
158158
Permissions.Endpoints.Token,
159159
Permissions.GrantTypes.AuthorizationCode,
160160
Permissions.ResponseTypes.Code,

0 commit comments

Comments
 (0)