Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ resharper_csharp_align_multiline_argument=false
resharper_csharp_align_multiline_expression=false
resharper_csharp_align_multiline_parameter=false
resharper_csharp_align_multiple_declaration=false
resharper_csharp_max_line_length=120
resharper_csharp_max_line_length=160
resharper_csharp_naming_rule.enum_member=AaBb
resharper_csharp_naming_rule.method_property_event=AaBb
resharper_csharp_naming_rule.other=AaBb
Expand Down Expand Up @@ -412,7 +412,7 @@ resharper_format_leading_spaces_decl=false
resharper_html_attribute_indent=align_by_first_attribute
resharper_html_linebreak_before_elements=body,div,p,form,h1,h2,h3
resharper_html_max_blank_lines_between_tags=2
resharper_html_max_line_length=120
resharper_html_max_line_length=160
resharper_html_pi_attribute_style=on_single_line
resharper_html_space_before_self_closing=false
resharper_html_wrap_lines=true
Expand Down Expand Up @@ -619,7 +619,7 @@ resharper_vb_align_multiline_argument=true
resharper_vb_align_multiline_expression=true
resharper_vb_align_multiline_parameter=true
resharper_vb_align_multiple_declaration=true
resharper_vb_max_line_length=120
resharper_vb_max_line_length=160
resharper_vb_place_field_attribute_on_same_line=true
resharper_vb_place_method_attribute_on_same_line=false
resharper_vb_place_type_attribute_on_same_line=false
Expand Down Expand Up @@ -659,7 +659,7 @@ resharper_wrap_verbatim_interpolated_strings=no_wrap
resharper_xmldoc_attribute_indent=single_indent
resharper_xmldoc_linebreak_before_elements=summary,remarks,example,returns,param,typeparam,value,para
resharper_xmldoc_max_blank_lines_between_tags=0
resharper_xmldoc_max_line_length=120
resharper_xmldoc_max_line_length=160
resharper_xmldoc_pi_attribute_style=do_not_touch
resharper_xmldoc_space_before_self_closing=true
resharper_xmldoc_wrap_lines=true
Expand All @@ -668,7 +668,7 @@ resharper_xmldoc_wrap_text=true
resharper_xml_attribute_indent=align_by_first_attribute
resharper_xml_linebreak_before_elements=
resharper_xml_max_blank_lines_between_tags=2
resharper_xml_max_line_length=120
resharper_xml_max_line_length=160
resharper_xml_pi_attribute_style=do_not_touch
resharper_xml_space_before_self_closing=true
resharper_xml_wrap_lines=true
Expand Down
26 changes: 13 additions & 13 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<FrameworkVersion>8.0.19</FrameworkVersion>
<FrameworkVersion>8.0.27</FrameworkVersion>
</PropertyGroup>

<ItemGroup>
<!--build related-->
<PackageReference Include="MinVer" Version="6.0.0" PrivateAssets="All"/>
<PackageReference Update="SimpleExec" Version="12.0.0"/>
<PackageReference Update="Bullseye" Version="6.0.0"/>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
<PackageReference Include="MinVer" Version="7.0.0" PrivateAssets="All"/>
<PackageReference Update="SimpleExec" Version="13.0.0"/>
<PackageReference Update="Bullseye" Version="6.1.0"/>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="10.0.300" PrivateAssets="All"/>

<!--our stuff -->
<PackageReference Update="IdentityModel" Version="6.1.0"/>
Expand Down Expand Up @@ -40,19 +40,19 @@
<PackageReference Update="Microsoft.EntityFrameworkCore.SqlServer" Version="$(FrameworkVersion)"/>
<PackageReference Update="Microsoft.EntityFrameworkCore.Design" Version="$(FrameworkVersion)" PrivateAssets="All"/>

<PackageReference Update="Serilog" Version="4.3.0"/>
<PackageReference Update="Serilog" Version="4.3.1"/>
<PackageReference Update="Serilog.AspNetCore" Version="8.0.3"/>
<PackageReference Update="Serilog.Sinks.Console" Version="6.0.0"/>
<PackageReference Update="Serilog.Sinks.Console" Version="6.1.1"/>
<PackageReference Update="Serilog.Sinks.File" Version="7.0.0"/>

<!--unsorted -->
<PackageReference Update="FluentAssertions" Version="8.6.0"/>
<PackageReference Update="FluentAssertions" Version="8.10.0"/>
<PackageReference Update="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="$(FrameworkVersion)"/>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.14.1"/>
<PackageReference Update="xunit.v3" Version="3.0.0"/>
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="8.13.1"/>
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.13.1"/>
<PackageReference Update="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="18.6.0"/>
<PackageReference Update="xunit.v3" Version="3.2.2"/>
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="8.18.0"/>
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="8.18.0"/>
<PackageReference Update="Newtonsoft.Json" Version="13.0.4"/>

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using IdentityServer4.Configuration;
using Microsoft.Extensions.Configuration;
using System;
using Dex.RfcExceptionsHandler.Extensions;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
Expand Down Expand Up @@ -33,6 +34,8 @@ public static IIdentityServerBuilder AddIdentityServerBuilder(this IServiceColle
/// <returns></returns>
public static IIdentityServerBuilder AddIdentityServer(this IServiceCollection services)
{
services.AddDefaultRfcExceptionHandleMiddleware();

var builder = services.AddIdentityServerBuilder();

builder
Expand Down Expand Up @@ -83,10 +86,9 @@ public static IIdentityServerBuilder AddIdentityServer(this IServiceCollection s
/// <param name="schemes">The schemes to configure. If none provided, then all OpenIdConnect schemes will use the cache.</param>
public static IServiceCollection AddOidcStateDataFormatterCache(this IServiceCollection services, params string[] schemes)
{
services.AddSingleton<IPostConfigureOptions<OpenIdConnectOptions>>(
svcs => new ConfigureOpenIdConnectOptions(
schemes,
svcs.GetRequiredService<IHttpContextAccessor>())
services.AddSingleton<IPostConfigureOptions<OpenIdConnectOptions>>(svcs => new ConfigureOpenIdConnectOptions(
schemes,
svcs.GetRequiredService<IHttpContextAccessor>())
);

return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using Dex.RfcExceptionsHandler.Extensions;

namespace Microsoft.AspNetCore.Builder;

Expand All @@ -26,9 +27,10 @@
/// <param name="app">The application.</param>
/// <param name="options">The options.</param>
/// <returns></returns>
public static IApplicationBuilder UseIdentityServer(this IApplicationBuilder app, IdentityServerMiddlewareOptions options = null)

Check warning on line 30 in src/IdentityServer4/src/Configuration/IdentityServerApplicationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build_nuget

Cannot convert null literal to non-nullable reference type.
{
app.Validate();
app.UseRfcExceptionHandleMiddleware();

app.UseMiddleware<BaseUrlMiddleware>();

Expand All @@ -54,21 +56,26 @@
if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory));

var logger = loggerFactory.CreateLogger("IdentityServer4.Startup");
logger.LogInformation("Starting IdentityServer4 version {version}", typeof(IdentityServerMiddleware).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);
logger.LogInformation("Starting IdentityServer4 version {version}",
typeof(IdentityServerMiddleware).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion);

var scopeFactory = app.ApplicationServices.GetService<IServiceScopeFactory>();

using var scope = scopeFactory.CreateScope();
var serviceProvider = scope.ServiceProvider;

TestService(serviceProvider, typeof(IPersistedGrantStore), logger, "No storage mechanism for grants specified. Use the 'AddInMemoryPersistedGrants' extension method to register a development version.");
TestService(serviceProvider, typeof(IClientStore), logger, "No storage mechanism for clients specified. Use the 'AddInMemoryClients' extension method to register a development version.");
TestService(serviceProvider, typeof(IResourceStore), logger, "No storage mechanism for resources specified. Use the 'AddInMemoryIdentityResources' or 'AddInMemoryApiResources' extension method to register a development version.");
TestService(serviceProvider, typeof(IPersistedGrantStore), logger,
"No storage mechanism for grants specified. Use the 'AddInMemoryPersistedGrants' extension method to register a development version.");
TestService(serviceProvider, typeof(IClientStore), logger,
"No storage mechanism for clients specified. Use the 'AddInMemoryClients' extension method to register a development version.");
TestService(serviceProvider, typeof(IResourceStore), logger,
"No storage mechanism for resources specified. Use the 'AddInMemoryIdentityResources' or 'AddInMemoryApiResources' extension method to register a development version.");

var persistedGrants = serviceProvider.GetService(typeof(IPersistedGrantStore));
if (persistedGrants.GetType().FullName == typeof(InMemoryPersistedGrantStore).FullName)
{
logger.LogInformation("You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.");
logger.LogInformation(
"You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.");
}

var options = serviceProvider.GetRequiredService<IdentityServerOptions>();
Expand All @@ -85,7 +92,8 @@

if (await schemes.GetDefaultAuthenticateSchemeAsync() == null && options.Authentication.CookieAuthenticationScheme == null)
{
logger.LogWarning("No authentication scheme has been set. Setting either a default authentication scheme or a CookieAuthenticationScheme on IdentityServerOptions is required.");
logger.LogWarning(
"No authentication scheme has been set. Setting either a default authentication scheme or a CookieAuthenticationScheme on IdentityServerOptions is required.");
}
else
{
Expand All @@ -94,7 +102,8 @@
if (options.Authentication.CookieAuthenticationScheme != null)
{
authenticationScheme = await schemes.GetSchemeAsync(options.Authentication.CookieAuthenticationScheme);
logger.LogInformation("Using explicitly configured authentication scheme {scheme} for IdentityServer", options.Authentication.CookieAuthenticationScheme);
logger.LogInformation("Using explicitly configured authentication scheme {scheme} for IdentityServer",
options.Authentication.CookieAuthenticationScheme);
}
else
{
Expand All @@ -104,7 +113,9 @@

if (!typeof(IAuthenticationSignInHandler).IsAssignableFrom(authenticationScheme.HandlerType))
{
logger.LogInformation("Authentication scheme {scheme} is configured for IdentityServer, but it is not a scheme that supports signin (like cookies). If you support interactive logins via the browser, then a cookie-based scheme should be used.", authenticationScheme.Name);
logger.LogInformation(
"Authentication scheme {scheme} is configured for IdentityServer, but it is not a scheme that supports signin (like cookies). If you support interactive logins via the browser, then a cookie-based scheme should be used.",
authenticationScheme.Name);
}

logger.LogDebug("Using {scheme} as default ASP.NET Core scheme for authentication", (await schemes.GetDefaultAuthenticateSchemeAsync())?.Name);
Expand All @@ -118,7 +129,7 @@
private static void ValidateOptions(IdentityServerOptions options, ILogger logger)
{
if (options.IssuerUri.IsPresent()) logger.LogDebug("Custom IssuerUri set to {0}", options.IssuerUri);

// todo: perhaps different logging messages?
//if (options.UserInteraction.LoginUrl.IsMissing()) throw new InvalidOperationException("LoginUrl is not configured");
//if (options.UserInteraction.LoginReturnUrlParameter.IsMissing()) throw new InvalidOperationException("LoginReturnUrlParameter is not configured");
Expand All @@ -128,14 +139,15 @@
if (options.UserInteraction.ErrorIdParameter.IsMissing()) throw new InvalidOperationException("ErrorIdParameter is not configured");
if (options.UserInteraction.ConsentUrl.IsMissing()) throw new InvalidOperationException("ConsentUrl is not configured");
if (options.UserInteraction.ConsentReturnUrlParameter.IsMissing()) throw new InvalidOperationException("ConsentReturnUrlParameter is not configured");
if (options.UserInteraction.CustomRedirectReturnUrlParameter.IsMissing()) throw new InvalidOperationException("CustomRedirectReturnUrlParameter is not configured");
if (options.UserInteraction.CustomRedirectReturnUrlParameter.IsMissing())
throw new InvalidOperationException("CustomRedirectReturnUrlParameter is not configured");

if (options.Authentication.CheckSessionCookieName.IsMissing()) throw new InvalidOperationException("CheckSessionCookieName is not configured");

if (options.Cors.CorsPolicyName.IsMissing()) throw new InvalidOperationException("CorsPolicyName is not configured");
}

internal static object TestService(IServiceProvider serviceProvider, Type service, ILogger logger, string message = null, bool doThrow = true)

Check warning on line 150 in src/IdentityServer4/src/Configuration/IdentityServerApplicationBuilderExtensions.cs

View workflow job for this annotation

GitHub Actions / build_nuget

Cannot convert null literal to non-nullable reference type.
{
var appService = serviceProvider.GetService(service);

Expand Down
1 change: 1 addition & 0 deletions src/IdentityServer4/src/IdentityServer4.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dex.RfcExceptionsHandler" Version="8.0.1" />
<PackageReference Include="IdentityModel"/>
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,8 +1058,8 @@ public async Task overlapping_identity_scopes_and_api_scopes_should_show_error_p
"123_state",
"123_nonce");

Func<Task> a = () => _mockPipeline.BrowserClient.GetAsync(url, TestContext.Current.CancellationToken);
await a.Should().ThrowAsync<Exception>();
var response = await _mockPipeline.BrowserClient.GetAsync(url, TestContext.Current.CancellationToken);
response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
}

[Fact]
Expand Down
Loading