Skip to content

Commit

Permalink
Provide a more DI-friendly interface to the objects in this library (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
j3parker committed Sep 13, 2021
1 parent 4cd88e2 commit 1cbea43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 41 deletions.
6 changes: 5 additions & 1 deletion src/D2L.Security.OAuth2/Keys/Default/TokenSigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
using D2L.Security.OAuth2.Validation.Exceptions;

namespace D2L.Security.OAuth2.Keys.Default {
internal sealed class TokenSigner : ITokenSigner {
public sealed class TokenSigner : ITokenSigner {

private readonly IPrivateKeyProvider m_privateKeyProvider;

public TokenSigner(
IKeyManagementService keyManagementService
) : this( (IPrivateKeyProvider)keyManagementService ) {}

internal TokenSigner(
IPrivateKeyProvider privateKeyProvider
) {
m_privateKeyProvider = privateKeyProvider;
Expand Down
20 changes: 18 additions & 2 deletions src/D2L.Security.OAuth2/Keys/KeyManagementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
using System.Threading.Tasks;

namespace D2L.Security.OAuth2.Keys {
internal sealed class KeyManagementService : IKeyManagementService, IPrivateKeyProvider, IDisposable {
public sealed class KeyManagementService : IKeyManagementService, IPrivateKeyProvider, IDisposable {
private readonly IPublicKeyDataProvider m_publicKeys;
private readonly IPrivateKeyDataProvider m_privateKeys;
private readonly IDateTimeProvider m_clock;
private readonly OAuth2Configuration m_config;

private D2LSecurityToken m_current = null;

public KeyManagementService(
internal KeyManagementService(
IPublicKeyDataProvider publicKeys,
IPrivateKeyDataProvider privateKeys,
IDateTimeProvider clock,
Expand All @@ -28,6 +28,22 @@ OAuth2Configuration config
m_config = config;
}

// Constructor for use outside of this library.
// We are hiding our mockable clock interface for now, but we could
// re-evaluate that in the future.
public KeyManagementService(
IPublicKeyDataProvider publicKeys,
IPrivateKeyDataProvider privateKeys,
OAuth2Configuration config = null
) : this(
publicKeys,
privateKeys,
new DateTimeProvider(),
config ?? new OAuth2Configuration()
) {
config.CheckSanity();
}

async Task<D2LSecurityToken> IPrivateKeyProvider.GetSigningCredentialsAsync() {
var current = Volatile.Read( ref m_current );

Expand Down
38 changes: 0 additions & 38 deletions src/D2L.Security.OAuth2/OAuth2Factory.cs

This file was deleted.

0 comments on commit 1cbea43

Please sign in to comment.