Skip to content

Commit c4a5534

Browse files
committed
Upgrade package
1 parent 4b1d8a4 commit c4a5534

File tree

168 files changed

+877
-2336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+877
-2336
lines changed

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<add key="Zero" value="https://www.myget.org/F/zero/api/v3/index.json" />
77
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
88
<add key="AspNetCoreTools" value="https://dotnet.myget.org/F/aspnetcore-tools/api/v3/index.json" />
9+
<add key="Identity* Dev Feed" value="https://www.myget.org/F/identity/" />
910
</packageSources>
1011
</configuration>

SourceLink/IdentityServer4/Configuration/DependencyInjection/BuilderExtensions/Core.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public static IIdentityServerBuilder AddValidators(this IIdentityServerBuilder b
190190
builder.Services.TryAddTransient<IResourceOwnerPasswordValidator, NotSupportedResourceOwnerPasswordValidator>();
191191
builder.Services.TryAddTransient<ICustomTokenRequestValidator, DefaultCustomTokenRequestValidator>();
192192
builder.Services.TryAddTransient<IUserInfoRequestValidator, UserInfoRequestValidator>();
193-
builder.Services.TryAddTransient<IClientConfigurationValidator, NopClientConfigurationValidator>();
193+
builder.Services.TryAddTransient<IClientConfigurationValidator, DefaultClientConfigurationValidator>();
194194

195195
// optional
196196
builder.Services.TryAddTransient<ICustomTokenValidator, DefaultCustomTokenValidator>();

SourceLink/IdentityServer4/Configuration/DependencyInjection/ConfigureInternalCookieOptions.cs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using IdentityServer4.Extensions;
1+
using IdentityServer4.Extensions;
22
using Microsoft.AspNetCore.Authentication.Cookies;
33
using Microsoft.AspNetCore.Http;
4+
using Microsoft.Extensions.Logging;
45
using Microsoft.Extensions.Options;
56

67
namespace IdentityServer4.Configuration
@@ -25,15 +26,27 @@ public void Configure(string name, CookieAuthenticationOptions options)
2526
options.SlidingExpiration = _idsrv.Authentication.CookieSlidingExpiration;
2627
options.ExpireTimeSpan = _idsrv.Authentication.CookieLifetime;
2728
options.Cookie.Name = IdentityServerConstants.DefaultCookieAuthenticationScheme;
29+
options.Cookie.IsEssential = true;
2830
options.Cookie.SameSite = SameSiteMode.None;
31+
2932
options.LoginPath = ExtractLocalUrl(_idsrv.UserInteraction.LoginUrl);
3033
options.LogoutPath = ExtractLocalUrl(_idsrv.UserInteraction.LogoutUrl);
31-
options.ReturnUrlParameter = _idsrv.UserInteraction.LoginReturnUrlParameter;
34+
if (_idsrv.UserInteraction.LoginReturnUrlParameter != null)
35+
{
36+
options.ReturnUrlParameter = _idsrv.UserInteraction.LoginReturnUrlParameter;
37+
}
3238
}
3339

3440
if (name == IdentityServerConstants.ExternalCookieAuthenticationScheme)
3541
{
3642
options.Cookie.Name = IdentityServerConstants.ExternalCookieAuthenticationScheme;
43+
options.Cookie.IsEssential = true;
44+
// https://github.com/IdentityServer/IdentityServer4/issues/2595
45+
// need to set None because iOS 12 safari considers the POST back to the client from the
46+
// IdP as not safe, so cookies issued from response (with lax) then should not be honored.
47+
// so we need to make those cookies issued without same-site, thus the browser will
48+
// hold onto them and send on the next redirect to the callback page.
49+
options.Cookie.SameSite = SameSiteMode.None;
3750
}
3851
}
3952

@@ -57,40 +70,41 @@ internal class PostConfigureInternalCookieOptions : IPostConfigureOptions<Cookie
5770
{
5871
private readonly IdentityServerOptions _idsrv;
5972
private readonly IOptions<Microsoft.AspNetCore.Authentication.AuthenticationOptions> _authOptions;
73+
private readonly ILogger _logger;
6074

61-
public PostConfigureInternalCookieOptions(IdentityServerOptions idsrv, IOptions<Microsoft.AspNetCore.Authentication.AuthenticationOptions> authOptions)
75+
public PostConfigureInternalCookieOptions(
76+
IdentityServerOptions idsrv,
77+
IOptions<Microsoft.AspNetCore.Authentication.AuthenticationOptions> authOptions,
78+
ILoggerFactory loggerFactory)
6279
{
6380
_idsrv = idsrv;
6481
_authOptions = authOptions;
82+
_logger = loggerFactory.CreateLogger("IdentityServer4.Startup");
83+
6584
}
6685

6786
public void PostConfigure(string name, CookieAuthenticationOptions options)
6887
{
69-
var scheme = _authOptions.Value.DefaultAuthenticateScheme ??
88+
var scheme = _idsrv.Authentication.CookieAuthenticationScheme ??
89+
_authOptions.Value.DefaultAuthenticateScheme ??
7090
_authOptions.Value.DefaultScheme;
7191

7292
if (name == scheme)
7393
{
74-
options.LoginPath = ExtractLocalUrl(_idsrv.UserInteraction.LoginUrl);
75-
options.LogoutPath = ExtractLocalUrl(_idsrv.UserInteraction.LogoutUrl);
76-
options.ReturnUrlParameter = _idsrv.UserInteraction.LoginReturnUrlParameter;
77-
}
78-
}
94+
_idsrv.UserInteraction.LoginUrl = _idsrv.UserInteraction.LoginUrl ?? options.LoginPath;
95+
_idsrv.UserInteraction.LoginReturnUrlParameter = _idsrv.UserInteraction.LoginReturnUrlParameter ?? options.ReturnUrlParameter;
96+
_idsrv.UserInteraction.LogoutUrl = _idsrv.UserInteraction.LogoutUrl ?? options.LogoutPath;
7997

80-
private static string ExtractLocalUrl(string url)
81-
{
82-
if (url.IsLocalUrl())
83-
{
84-
if (url.StartsWith("~/"))
85-
{
86-
url = url.Substring(1);
87-
}
98+
_logger.LogDebug("Login Url: {url}", _idsrv.UserInteraction.LoginUrl);
99+
_logger.LogDebug("Login Return Url Parameter: {param}", _idsrv.UserInteraction.LoginReturnUrlParameter);
100+
_logger.LogDebug("Logout Url: {url}", _idsrv.UserInteraction.LogoutUrl);
88101

89-
return url;
90-
}
102+
_logger.LogDebug("ConsentUrl Url: {url}", _idsrv.UserInteraction.ConsentUrl);
103+
_logger.LogDebug("Consent Return Url Parameter: {param}", _idsrv.UserInteraction.ConsentReturnUrlParameter);
91104

92-
return null;
105+
_logger.LogDebug("Error Url: {url}", _idsrv.UserInteraction.ErrorUrl);
106+
_logger.LogDebug("Error Id Parameter: {param}", _idsrv.UserInteraction.ErrorIdParameter);
107+
}
93108
}
94109
}
95-
96110
}

SourceLink/IdentityServer4/Configuration/DependencyInjection/Options/AuthenticationOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ namespace IdentityServer4.Configuration
1111
/// </summary>
1212
public class AuthenticationOptions
1313
{
14+
/// <summary>
15+
/// Sets the cookie authenitcation scheme confgured by the host used for interactive users. If not set, the scheme will inferred from the host's default authentication scheme.
16+
/// This setting is typically used when AddPolicyScheme is used in the host as the default scheme.
17+
/// </summary>
18+
public string CookieAuthenticationScheme { get; set; }
19+
1420
/// <summary>
1521
/// Sets the cookie lifetime (only effective if the IdentityServer-provided cookie handler is used)
1622
/// </summary>

SourceLink/IdentityServer4/Configuration/DependencyInjection/Options/IdentityServerOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44

@@ -96,5 +96,10 @@ public class IdentityServerOptions
9696
/// Gets or sets the Content Security Policy options.
9797
/// </summary>
9898
public CspOptions Csp { get; set; } = new CspOptions();
99+
100+
/// <summary>
101+
/// Gets or sets the validation options.
102+
/// </summary>
103+
public ValidationOptions Validation { get; set; } = new ValidationOptions();
99104
}
100105
}

SourceLink/IdentityServer4/Configuration/DependencyInjection/Options/UserInteractionOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44

@@ -17,23 +17,23 @@ public class UserInteractionOptions
1717
/// <value>
1818
/// The login URL.
1919
/// </value>
20-
public string LoginUrl { get; set; } = Constants.UIConstants.DefaultRoutePaths.Login.EnsureLeadingSlash();
20+
public string LoginUrl { get; set; } //= Constants.UIConstants.DefaultRoutePaths.Login.EnsureLeadingSlash();
2121

2222
/// <summary>
2323
/// Gets or sets the login return URL parameter.
2424
/// </summary>
2525
/// <value>
2626
/// The login return URL parameter.
2727
/// </value>
28-
public string LoginReturnUrlParameter { get; set; } = Constants.UIConstants.DefaultRoutePathParams.Login;
28+
public string LoginReturnUrlParameter { get; set; } //= Constants.UIConstants.DefaultRoutePathParams.Login;
2929

3030
/// <summary>
3131
/// Gets or sets the logout URL. If a local URL, the value must start with a leading slash.
3232
/// </summary>
3333
/// <value>
3434
/// The logout URL.
3535
/// </value>
36-
public string LogoutUrl { get; set; } = Constants.UIConstants.DefaultRoutePaths.Logout.EnsureLeadingSlash();
36+
public string LogoutUrl { get; set; } //= Constants.UIConstants.DefaultRoutePaths.Logout.EnsureLeadingSlash();
3737

3838
/// <summary>
3939
/// Gets or sets the logout identifier parameter.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
3+
4+
5+
using System.Collections.Generic;
6+
7+
namespace IdentityServer4.Configuration
8+
{
9+
/// <summary>
10+
/// The ValidationOptions contains settings that affect some of the default validation behavior.
11+
/// </summary>
12+
public class ValidationOptions
13+
{
14+
/// <summary>
15+
/// Collection of URI scheme prefixes that should never be used as custom URI schemes in the redirect_uri passed to tha authorize endpoint.
16+
/// </summary>
17+
public ICollection<string> InvalidRedirectUriPrefixes { get; } = new HashSet<string>
18+
{
19+
"javascript:",
20+
"file:",
21+
"data:",
22+
"mailto:",
23+
"ftp:",
24+
"blob:",
25+
"about:",
26+
"ssh:",
27+
"tel:",
28+
"view-source:",
29+
"ws:",
30+
"wss:"
31+
};
32+
}
33+
}

SourceLink/IdentityServer4/Configuration/IdentityServerApplicationBuilderExtensions.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,25 @@ internal static void Validate(this IApplicationBuilder app)
7676

7777
private static async Task ValidateAsync(IServiceProvider services, ILogger logger)
7878
{
79+
var options = services.GetRequiredService<IdentityServerOptions>();
7980
var schemes = services.GetRequiredService<IAuthenticationSchemeProvider>();
8081

81-
if (await schemes.GetDefaultAuthenticateSchemeAsync() == null)
82+
if (await schemes.GetDefaultAuthenticateSchemeAsync() == null && options.Authentication.CookieAuthenticationScheme == null)
8283
{
83-
logger.LogWarning("No default authentication scheme has been set. Setting a default scheme is required.");
84+
logger.LogWarning("No authentication scheme has been set. Setting either a default authentication scheme or a CookieAuthenticationScheme on IdentityServerOptions is required.");
8485
}
8586
else
8687
{
87-
logger.LogDebug("Using {scheme} as default scheme for authentication", (await schemes.GetDefaultAuthenticateSchemeAsync())?.Name);
88-
logger.LogDebug("Using {scheme} as default scheme for sign-in", (await schemes.GetDefaultSignInSchemeAsync())?.Name);
89-
logger.LogDebug("Using {scheme} as default scheme for sign-out", (await schemes.GetDefaultSignOutSchemeAsync())?.Name);
90-
logger.LogDebug("Using {scheme} as default scheme for challenge", (await schemes.GetDefaultChallengeSchemeAsync())?.Name);
91-
logger.LogDebug("Using {scheme} as default scheme for forbid", (await schemes.GetDefaultForbidSchemeAsync())?.Name);
88+
if (options.Authentication.CookieAuthenticationScheme != null)
89+
{
90+
logger.LogInformation("Using explicitly configured scheme {scheme} for IdentityServer", options.Authentication.CookieAuthenticationScheme);
91+
}
92+
93+
logger.LogDebug("Using {scheme} as default ASP.NET Core scheme for authentication", (await schemes.GetDefaultAuthenticateSchemeAsync())?.Name);
94+
logger.LogDebug("Using {scheme} as default ASP.NET Core scheme for sign-in", (await schemes.GetDefaultSignInSchemeAsync())?.Name);
95+
logger.LogDebug("Using {scheme} as default ASP.NET Core scheme for sign-out", (await schemes.GetDefaultSignOutSchemeAsync())?.Name);
96+
logger.LogDebug("Using {scheme} as default ASP.NET Core scheme for challenge", (await schemes.GetDefaultChallengeSchemeAsync())?.Name);
97+
logger.LogDebug("Using {scheme} as default ASP.NET Core scheme for forbid", (await schemes.GetDefaultForbidSchemeAsync())?.Name);
9298
}
9399
}
94100

@@ -106,9 +112,10 @@ private static void ValidateOptions(IdentityServerOptions options, ILogger logge
106112
logger.LogDebug("PublicOrigin explicitly set to {0}", options.PublicOrigin);
107113
}
108114

109-
if (options.UserInteraction.LoginUrl.IsMissing()) throw new InvalidOperationException("LoginUrl is not configured");
110-
if (options.UserInteraction.LoginReturnUrlParameter.IsMissing()) throw new InvalidOperationException("LoginReturnUrlParameter is not configured");
111-
if (options.UserInteraction.LogoutUrl.IsMissing()) throw new InvalidOperationException("LogoutUrl is not configured");
115+
// todo: perhaps different logging messages?
116+
//if (options.UserInteraction.LoginUrl.IsMissing()) throw new InvalidOperationException("LoginUrl is not configured");
117+
//if (options.UserInteraction.LoginReturnUrlParameter.IsMissing()) throw new InvalidOperationException("LoginReturnUrlParameter is not configured");
118+
//if (options.UserInteraction.LogoutUrl.IsMissing()) throw new InvalidOperationException("LogoutUrl is not configured");
112119
if (options.UserInteraction.LogoutIdParameter.IsMissing()) throw new InvalidOperationException("LogoutIdParameter is not configured");
113120
if (options.UserInteraction.ErrorUrl.IsMissing()) throw new InvalidOperationException("ErrorUrl is not configured");
114121
if (options.UserInteraction.ErrorIdParameter.IsMissing()) throw new InvalidOperationException("ErrorIdParameter is not configured");

SourceLink/IdentityServer4/Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal static class Constants
1414
public const string IdentityServerName = "IdentityServer4";
1515
public const string IdentityServerAuthenticationType = IdentityServerName;
1616
public const string ExternalAuthenticationMethod = "external";
17-
public const string AccessTokenAudience = "{0}resources";
1817
public const string DefaultHashAlgorithm = "SHA256";
1918

2019
public static readonly TimeSpan DefaultCookieTimeSpan = TimeSpan.FromHours(10);

SourceLink/IdentityServer4/Endpoints/Results/CustomRedirectResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
1+
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
33

44

@@ -66,7 +66,7 @@ public Task ExecuteAsync(HttpContext context)
6666
{
6767
Init(context);
6868

69-
var returnUrl = context.Request.PathBase.ToString().EnsureTrailingSlash() + Constants.ProtocolRoutePaths.Authorize;
69+
var returnUrl = context.GetIdentityServerBasePath().EnsureTrailingSlash() + Constants.ProtocolRoutePaths.Authorize;
7070
returnUrl = returnUrl.AddQueryString(_request.Raw.ToQueryString());
7171

7272
if (!_url.IsLocalUrl())

0 commit comments

Comments
 (0)