Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple valid token issuers #1590

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public class IdentityServerOptions
/// </value>
public string? IssuerUri { get; set; }

/// <summary>
/// Gets or sets the list of valid issuers, e.g. https://myissuer.com.
/// If not set, the issuer name is inferred from the request
/// </summary>
/// <value>
/// List of valid issuers, e.g. https://myissuer.com
/// </value>
public string[]? ValidIssuers { get; set; }

/// <summary>
/// Set to false to preserve the original casing of the IssuerUri. Defaults to true.
/// </summary>
Expand Down
24 changes: 23 additions & 1 deletion src/IdentityServer/Services/Default/DefaultIssuerNameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


using System;
using System.Linq;
using System.Threading.Tasks;
using Duende.IdentityServer.Configuration;
using Duende.IdentityServer.Extensions;
Expand Down Expand Up @@ -31,7 +32,7 @@ public DefaultIssuerNameService(IdentityServerOptions options, IServerUrls urls,
_urls = urls;
_httpContextAccessor = httpContextAccessor;
}

/// <inheritdoc />
public Task<string> GetCurrentAsync()
{
Expand Down Expand Up @@ -75,4 +76,25 @@ public Task<string> GetCurrentAsync()

return Task.FromResult(issuer);
}

/// <inheritdoc />
public Task<string[]> GetListAsync()
{
// if they've explicitly configured a URI then use it,
// otherwise dynamically calculate it
var issuers = _options.ValidIssuers;

if (issuers == null || issuers.Length < 1)
{
issuers = [GetCurrentAsync().Result];

}
else if (_options.LowerCaseIssuerUri)
{
issuers = issuers.Select(x => x.ToLowerInvariant()).ToArray();
}


return Task.FromResult(issuers);
}
}
6 changes: 6 additions & 0 deletions src/IdentityServer/Services/IIssuerNameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ public interface IIssuerNameService
/// </summary>
/// <returns></returns>
Task<string> GetCurrentAsync();

/// <summary>
/// Returns the list of valid issuers
/// </summary>
/// <returns></returns>
Task<string[]> GetListAsync();
}
1 change: 1 addition & 0 deletions src/IdentityServer/Validation/Default/TokenValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private async Task<TokenValidationResult> ValidateJwtAsync(string jwtString,
var parameters = new TokenValidationParameters
{
ValidIssuer = await _issuerNameService.GetCurrentAsync(),
ValidIssuers = await _issuerNameService.GetListAsync(),
IssuerSigningKeys = validationKeys.Select(k => k.Key),
ValidateLifetime = validateLifetime
};
Expand Down