Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit 2615d2c

Browse files
committed
Introduce a new AddCertificate extension accepting a X509KeyStorageFlags parameter
1 parent 85fb8c4 commit 2615d2c

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/AspNet.Security.OpenIdConnect.Server/OpenIdConnectServerExtensions.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ public static class OpenIdConnectServerExtensions
3535
/// <param name="builder">The authentication builder.</param>
3636
/// <returns>The authentication builder.</returns>
3737
public static AuthenticationBuilder AddOpenIdConnectServer([NotNull] this AuthenticationBuilder builder)
38-
{
39-
return builder.AddOpenIdConnectServer(OpenIdConnectServerDefaults.AuthenticationScheme);
40-
}
38+
=> builder.AddOpenIdConnectServer(OpenIdConnectServerDefaults.AuthenticationScheme);
4139

4240
/// <summary>
4341
/// Adds a new OpenID Connect server instance in the ASP.NET Core pipeline.
@@ -51,9 +49,7 @@ public static AuthenticationBuilder AddOpenIdConnectServer([NotNull] this Authen
5149
public static AuthenticationBuilder AddOpenIdConnectServer(
5250
[NotNull] this AuthenticationBuilder builder,
5351
[NotNull] Action<OpenIdConnectServerOptions> configuration)
54-
{
55-
return builder.AddOpenIdConnectServer(OpenIdConnectServerDefaults.AuthenticationScheme, configuration);
56-
}
52+
=> builder.AddOpenIdConnectServer(OpenIdConnectServerDefaults.AuthenticationScheme, configuration);
5753

5854
/// <summary>
5955
/// Adds a new OpenID Connect server instance in the ASP.NET Core pipeline.
@@ -64,9 +60,7 @@ public static AuthenticationBuilder AddOpenIdConnectServer(
6460
[EditorBrowsable(EditorBrowsableState.Advanced)]
6561
public static AuthenticationBuilder AddOpenIdConnectServer(
6662
[NotNull] this AuthenticationBuilder builder, [NotNull] string scheme)
67-
{
68-
return builder.AddOpenIdConnectServer(scheme, options => { });
69-
}
63+
=> builder.AddOpenIdConnectServer(scheme, options => { });
7064

7165
/// <summary>
7266
/// Adds a new OpenID Connect server instance in the ASP.NET Core pipeline.
@@ -155,6 +149,22 @@ public static IList<SigningCredentials> AddCertificate(
155149
public static IList<SigningCredentials> AddCertificate(
156150
[NotNull] this IList<SigningCredentials> credentials,
157151
[NotNull] Assembly assembly, [NotNull] string resource, [NotNull] string password)
152+
=> credentials.AddCertificate(assembly, resource, password, X509KeyStorageFlags.MachineKeySet);
153+
154+
/// <summary>
155+
/// Adds a specific <see cref="X509Certificate2"/> retrieved from an
156+
/// embedded resource to sign the tokens issued by the OpenID Connect server.
157+
/// </summary>
158+
/// <param name="credentials">The options used to configure the OpenID Connect server.</param>
159+
/// <param name="assembly">The assembly containing the certificate.</param>
160+
/// <param name="resource">The name of the embedded resource.</param>
161+
/// <param name="password">The password used to open the certificate.</param>
162+
/// <param name="flags">An enumeration of flags indicating how and where to store the private key of the certificate.</param>
163+
/// <returns>The signing credentials.</returns>
164+
public static IList<SigningCredentials> AddCertificate(
165+
[NotNull] this IList<SigningCredentials> credentials,
166+
[NotNull] Assembly assembly, [NotNull] string resource,
167+
[NotNull] string password, X509KeyStorageFlags flags)
158168
{
159169
if (credentials == null)
160170
{
@@ -183,7 +193,7 @@ public static IList<SigningCredentials> AddCertificate(
183193
throw new InvalidOperationException("The certificate was not found in the specified assembly.");
184194
}
185195

186-
return credentials.AddCertificate(stream, password);
196+
return credentials.AddCertificate(stream, password, flags);
187197
}
188198
}
189199

@@ -198,9 +208,7 @@ public static IList<SigningCredentials> AddCertificate(
198208
public static IList<SigningCredentials> AddCertificate(
199209
[NotNull] this IList<SigningCredentials> credentials,
200210
[NotNull] Stream stream, [NotNull] string password)
201-
{
202-
return credentials.AddCertificate(stream, password, X509KeyStorageFlags.MachineKeySet);
203-
}
211+
=> credentials.AddCertificate(stream, password, X509KeyStorageFlags.MachineKeySet);
204212

205213
/// <summary>
206214
/// Adds a specific <see cref="X509Certificate2"/> contained in

src/Owin.Security.OpenIdConnect.Server/OpenIdConnectServerExtensions.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ public static IList<SigningCredentials> AddCertificate(
129129
public static IList<SigningCredentials> AddCertificate(
130130
[NotNull] this IList<SigningCredentials> credentials,
131131
[NotNull] Assembly assembly, [NotNull] string resource, [NotNull] string password)
132+
=> credentials.AddCertificate(assembly, resource, password, X509KeyStorageFlags.MachineKeySet);
133+
134+
/// <summary>
135+
/// Adds a specific <see cref="X509Certificate2"/> retrieved from an
136+
/// embedded resource to sign the tokens issued by the OpenID Connect server.
137+
/// </summary>
138+
/// <param name="credentials">The options used to configure the OpenID Connect server.</param>
139+
/// <param name="assembly">The assembly containing the certificate.</param>
140+
/// <param name="resource">The name of the embedded resource.</param>
141+
/// <param name="password">The password used to open the certificate.</param>
142+
/// <param name="flags">An enumeration of flags indicating how and where to store the private key of the certificate.</param>
143+
/// <returns>The signing credentials.</returns>
144+
public static IList<SigningCredentials> AddCertificate(
145+
[NotNull] this IList<SigningCredentials> credentials,
146+
[NotNull] Assembly assembly, [NotNull] string resource,
147+
[NotNull] string password, X509KeyStorageFlags flags)
132148
{
133149
if (credentials == null)
134150
{
@@ -157,7 +173,7 @@ public static IList<SigningCredentials> AddCertificate(
157173
throw new InvalidOperationException("The certificate was not found in the specified assembly.");
158174
}
159175

160-
return credentials.AddCertificate(stream, password);
176+
return credentials.AddCertificate(stream, password, flags);
161177
}
162178
}
163179

@@ -172,9 +188,7 @@ public static IList<SigningCredentials> AddCertificate(
172188
public static IList<SigningCredentials> AddCertificate(
173189
[NotNull] this IList<SigningCredentials> credentials,
174190
[NotNull] Stream stream, [NotNull] string password)
175-
{
176-
return credentials.AddCertificate(stream, password, X509KeyStorageFlags.MachineKeySet);
177-
}
191+
=> credentials.AddCertificate(stream, password, X509KeyStorageFlags.MachineKeySet);
178192

179193
/// <summary>
180194
/// Adds a specific <see cref="X509Certificate2"/> contained in

0 commit comments

Comments
 (0)