diff --git a/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs b/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs index 754ee2214..5bfb5d886 100644 --- a/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs +++ b/src/IdentityServer/Configuration/DependencyInjection/BuilderExtensions/Core.cs @@ -190,7 +190,13 @@ public static IIdentityServerBuilder AddCoreServices(this IIdentityServerBuilder builder.Services.AddTransient(); builder.Services.AddTransient(); + +#pragma warning disable CS0618 // Type or member is obsolete + builder.Services.AddTransient(); + // We've added the IIdentityServerTools interface to allow mocking, but keep the old + // direct class registration around if anyone has a dependency on it. builder.Services.AddTransient(); +#pragma warning restore CS0618 // Type or member is obsolete builder.Services.AddTransient(); builder.Services.AddScoped(); diff --git a/src/IdentityServer/Extensions/IdentityServerToolsExtensions.cs b/src/IdentityServer/Extensions/IdentityServerToolsExtensions.cs index ec3db1d4b..4b841d117 100644 --- a/src/IdentityServer/Extensions/IdentityServerToolsExtensions.cs +++ b/src/IdentityServer/Extensions/IdentityServerToolsExtensions.cs @@ -13,9 +13,9 @@ namespace Duende.IdentityServer; /// -/// Extensions for IdentityServerTools +/// Extensions for IIdentityServerTools /// -public static class IdentityServerToolsExtensions +public static class IIdentityServerToolsExtensions { /// /// Issues the client JWT. @@ -27,7 +27,7 @@ public static class IdentityServerToolsExtensions /// The audiences. /// Additional claims /// - public static async Task IssueClientJwtAsync(this IdentityServerTools tools, + public static async Task IssueClientJwtAsync(this IIdentityServerTools tools, string clientId, int lifetime, IEnumerable scopes = null, diff --git a/src/IdentityServer/IdentityServerTools.cs b/src/IdentityServer/IdentityServerTools.cs index 990267a31..a07a85b0e 100644 --- a/src/IdentityServer/IdentityServerTools.cs +++ b/src/IdentityServer/IdentityServerTools.cs @@ -15,29 +15,10 @@ namespace Duende.IdentityServer; /// -/// Class for useful helpers for interacting with IdentityServer +/// Useful helpers for interacting with IdentityServer. /// -public class IdentityServerTools +public interface IIdentityServerTools { - internal readonly IServiceProvider ServiceProvider; - internal readonly IIssuerNameService IssuerNameService; - private readonly ITokenCreationService _tokenCreation; - private readonly IClock _clock; - - /// - /// Initializes a new instance of the class. - /// - /// The provider. - /// The issuer name service - /// The token creation service. - /// The clock. - public IdentityServerTools(IServiceProvider serviceProvider, IIssuerNameService issuerNameService, ITokenCreationService tokenCreation, IClock clock) - { - ServiceProvider = serviceProvider; - IssuerNameService = issuerNameService; - _tokenCreation = tokenCreation; - _clock = clock; - } /// /// Issues a JWT. @@ -46,11 +27,7 @@ public IdentityServerTools(IServiceProvider serviceProvider, IIssuerNameService /// The claims. /// /// claims - public virtual async Task IssueJwtAsync(int lifetime, IEnumerable claims) - { - var issuer = await IssuerNameService.GetCurrentAsync(); - return await IssueJwtAsync(lifetime, issuer, claims); - } + Task IssueJwtAsync(int lifetime, IEnumerable claims); /// /// Issues a JWT. @@ -60,11 +37,7 @@ public virtual async Task IssueJwtAsync(int lifetime, IEnumerable /// The claims. /// /// claims - public virtual Task IssueJwtAsync(int lifetime, string issuer, IEnumerable claims) - { - var tokenType = OidcConstants.TokenTypes.AccessToken; - return IssueJwtAsync(lifetime, issuer, tokenType, claims); - } + Task IssueJwtAsync(int lifetime, string issuer, IEnumerable claims); /// /// Issues a JWT. @@ -75,6 +48,58 @@ public virtual Task IssueJwtAsync(int lifetime, string issuer, IEnumerab /// The claims. /// /// claims + Task IssueJwtAsync(int lifetime, string issuer, string tokenType, IEnumerable claims); + + /// + /// Service Provider to resolve services. + /// + public IServiceProvider ServiceProvider { get; } + + /// + /// Issuer name service + /// + public IIssuerNameService IssuerNameService { get; } +} + +/// +/// Class for useful helpers for interacting with IdentityServer +/// +[Obsolete("Do not reference the IdentityServerTools implementation directly, use the IIdentityServerTools interface")] +public class IdentityServerTools : IIdentityServerTools +{ + /// + public IServiceProvider ServiceProvider { get; } + + /// + public IIssuerNameService IssuerNameService { get; } + + private readonly ITokenCreationService _tokenCreation; + private readonly IClock _clock; + + /// + public IdentityServerTools(IServiceProvider serviceProvider, IIssuerNameService issuerNameService, ITokenCreationService tokenCreation, IClock clock) + { + ServiceProvider = serviceProvider; + IssuerNameService = issuerNameService; + _tokenCreation = tokenCreation; + _clock = clock; + } + + /// + public virtual async Task IssueJwtAsync(int lifetime, IEnumerable claims) + { + var issuer = await IssuerNameService.GetCurrentAsync(); + return await IssueJwtAsync(lifetime, issuer, claims); + } + + /// + public virtual Task IssueJwtAsync(int lifetime, string issuer, IEnumerable claims) + { + var tokenType = OidcConstants.TokenTypes.AccessToken; + return IssueJwtAsync(lifetime, issuer, tokenType, claims); + } + + /// public virtual async Task IssueJwtAsync(int lifetime, string issuer, string tokenType, IEnumerable claims) { if (String.IsNullOrWhiteSpace(issuer)) throw new ArgumentNullException(nameof(issuer)); diff --git a/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs b/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs index c1977eeca..b80fc0034 100644 --- a/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs +++ b/src/IdentityServer/Services/Default/DefaultBackChannelLogoutService.cs @@ -31,7 +31,7 @@ public class DefaultBackChannelLogoutService : IBackChannelLogoutService /// /// The IdentityServerTools used to create and the JWT. /// - protected IdentityServerTools Tools { get; } + protected IIdentityServerTools Tools { get; } /// /// The ILogoutNotificationService to build the back channel logout requests. @@ -58,7 +58,7 @@ public class DefaultBackChannelLogoutService : IBackChannelLogoutService /// public DefaultBackChannelLogoutService( IClock clock, - IdentityServerTools tools, + IIdentityServerTools tools, ILogoutNotificationService logoutNotificationService, IBackChannelLogoutHttpClient backChannelLogoutHttpClient, ILogger logger) diff --git a/test/IdentityServer.IntegrationTests/Endpoints/Ciba/CibaTests.cs b/test/IdentityServer.IntegrationTests/Endpoints/Ciba/CibaTests.cs index 8e9062ef9..b7f087798 100644 --- a/test/IdentityServer.IntegrationTests/Endpoints/Ciba/CibaTests.cs +++ b/test/IdentityServer.IntegrationTests/Endpoints/Ciba/CibaTests.cs @@ -1428,7 +1428,7 @@ public async Task valid_id_token_hint_should_return_success() { _mockPipeline.Options.IssuerUri = IdentityServerPipeline.BaseUrl; - var tokenService = _mockPipeline.Resolve(); + var tokenService = _mockPipeline.Resolve(); var id_token = await tokenService.IssueJwtAsync(600, new Claim[] { new Claim("sub", _user.SubjectId), new Claim("aud", _cibaClient.ClientId),