Skip to content

Commit

Permalink
Remove ClaimSet helper (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
j3parker authored Nov 29, 2024
1 parent 4d4dcda commit 04e820f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 101 deletions.
47 changes: 0 additions & 47 deletions src/D2L.Security.OAuth2/Provisioning/ClaimSet.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using D2L.CodeStyle.Annotations;
using D2L.Security.OAuth2.Keys;
using D2L.Security.OAuth2.Scopes;
using D2L.Services;

namespace D2L.Security.OAuth2.Provisioning.Default {

Expand All @@ -23,15 +22,6 @@ IAuthServiceClient authServiceClient
m_client = authServiceClient;
}

[GenerateSync]
Task<IAccessToken> INonCachingAccessTokenProvider.ProvisionAccessTokenAsync(
ClaimSet claimSet,
IEnumerable<Scope> scopes
) {
var @this = this as INonCachingAccessTokenProvider;
return @this.ProvisionAccessTokenAsync( claimSet.ToClaims(), scopes );
}

[GenerateSync]
async Task<IAccessToken> INonCachingAccessTokenProvider.ProvisionAccessTokenAsync(
IEnumerable<Claim> claimSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using D2L.Security.OAuth2.Caching;
using D2L.Security.OAuth2.Scopes;
using D2L.Services;
using D2L.CodeStyle.Annotations;

#if DNXCORE50
Expand All @@ -33,16 +32,6 @@ TimeSpan tokenRefreshGracePeriod
m_tokenHandler = new JwtSecurityTokenHandler();
}

[GenerateSync]
async Task<IAccessToken> IAccessTokenProvider.ProvisionAccessTokenAsync(
ClaimSet claimSet,
IEnumerable<Scope> scopes,
ICache cache
) {
var @this = this as IAccessTokenProvider;
return await @this.ProvisionAccessTokenAsync( claimSet.ToClaims(), scopes, cache ).ConfigureAwait( false );
}

[GenerateSync]
async Task<IAccessToken> IAccessTokenProvider.ProvisionAccessTokenAsync(
IEnumerable<Claim> claims,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
using D2L.Security.OAuth2.Scopes;

namespace D2L.Security.OAuth2.Provisioning.Default {

internal partial interface INonCachingAccessTokenProvider {

[GenerateSync]
Task<IAccessToken> ProvisionAccessTokenAsync(
ClaimSet claimSet,
IEnumerable<Scope> scopes
);

[GenerateSync]
Task<IAccessToken> ProvisionAccessTokenAsync(
IEnumerable<Claim> claims,
Expand Down
18 changes: 0 additions & 18 deletions src/D2L.Security.OAuth2/Provisioning/IAccessTokenProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,11 @@
using D2L.Security.OAuth2.Scopes;

namespace D2L.Security.OAuth2.Provisioning {

/// <summary>
/// Provisions access tokens from the auth service
/// </summary>
/// <remarks>This type is disposable</remarks>
public partial interface IAccessTokenProvider {

/// <summary>
/// Provisions an access token containing the provided claims and scopes.
/// </summary>
/// <param name="claimSet">The set of claims to be included in the token.</param>
/// <param name="scopes">The set of scopes to be included in the token.</param>
/// <param name="cache">The provided <see cref="ICache"/> does not need to
/// check for token expiration or grace period because the
/// <see cref="IAccessTokenProvider"/> will handle it internally.</param>
/// <returns>An access token containing an expiry and the provided claims and scopes.</returns>
[GenerateSync]
Task<IAccessToken> ProvisionAccessTokenAsync(
ClaimSet claimSet,
IEnumerable<Scope> scopes,
ICache cache = null
);

/// <summary>
/// Provisions an access token containing the provided claims and scopes.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Net.Http;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Threading.Tasks;
using D2L.Security.OAuth2.Provisioning;
Expand All @@ -15,7 +16,12 @@ internal sealed class TestAccessTokenProviderTests {
private const string DEV_AUTH_JWKS_URL = "https://dev-auth.brightspace.com/core/.well-known/jwks";
private const string DEV_AUTH_JWK_URL = "https://dev-auth.brightspace.com/core/jwk/";

private readonly ClaimSet testClaimSet = new ClaimSet( "ExpandoClient", Guid.NewGuid() );
private readonly Claim[] testClaimSet = new[] {
new Claim( Constants.Claims.ISSUER, "ExpandoClient" ),
new Claim( Constants.Claims.TENANT_ID, Guid.NewGuid().ToString() )
};


private readonly Scope[] testScopes = {
new Scope( "*", "*", "*" )
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public async Task ProvisionAccessTokenAsync_CallPassThroughOverload_CallsOtherOv
m_serviceTokenCacheMock.Setup( x => x.GetAsync( key ) )
.Returns( Task.FromResult( new CacheResponse( true, BuildTestToken() ) ) );

ClaimSet claimSet = new ClaimSet( "TheIssuer" );
var claimSet = new[] {
new Claim( Constants.Claims.ISSUER, "TheIssuer" )
};

IAccessTokenProvider cachedAccessTokenProvider = GetCachedAccessTokenProvider();
IAccessToken token =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ await m_accessTokenProvider

[Test]
public async Task ProvisionAccessTokenAsync_LegacyClaimSetOverload_DoesRightThing() {
var claimSet = new ClaimSet(
issuer: TestData.ISSUER,
tenantId: TestData.TENANT_ID,
user: TestData.USER
);
var claimSet = new[] {
new Claim( Constants.Claims.ISSUER, TestData.ISSUER ),
new Claim( Constants.Claims.TENANT_ID, TestData.TENANT_ID.ToString() ),
new Claim(Constants.Claims.USER_ID, TestData.USER )
};

await m_accessTokenProvider
.ProvisionAccessTokenAsync( claimSet, new Scope[] { } )
Expand Down

0 comments on commit 04e820f

Please sign in to comment.