diff --git a/src/D2L.Security.OAuth2/Provisioning/ClaimSet.cs b/src/D2L.Security.OAuth2/Provisioning/ClaimSet.cs deleted file mode 100644 index fadd70a1..00000000 --- a/src/D2L.Security.OAuth2/Provisioning/ClaimSet.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; - -namespace D2L.Security.OAuth2.Provisioning { - /// - /// A structured holder of JWT claims - /// - public sealed class ClaimSet { - private readonly IList m_claims; - - /// - /// Constructs a new - /// - public ClaimSet( - string issuer, - Guid? tenantId = null, - string user = null - ) { - m_claims = new List(); - - if( string.IsNullOrWhiteSpace( issuer ) ) { - throw new ArgumentException( "Must pass a valid issuer", "issuer" ); - } - - m_claims.Add( new Claim( Constants.Claims.ISSUER, issuer ) ); - - if( tenantId.HasValue ) { - m_claims.Add( new Claim( Constants.Claims.TENANT_ID, tenantId.Value.ToString() ) ); - } - - if( !string.IsNullOrWhiteSpace( user ) ) { - m_claims.Add( new Claim( Constants.Claims.USER_ID, user ) ); - } - } - - /// - /// Converts the to an - /// - /// Claims as an - public IEnumerable ToClaims() { - return m_claims.ToArray(); - } - - } -} diff --git a/src/D2L.Security.OAuth2/Provisioning/Default/AccessTokenProvider.cs b/src/D2L.Security.OAuth2/Provisioning/Default/AccessTokenProvider.cs index 4f890e60..2be344fc 100644 --- a/src/D2L.Security.OAuth2/Provisioning/Default/AccessTokenProvider.cs +++ b/src/D2L.Security.OAuth2/Provisioning/Default/AccessTokenProvider.cs @@ -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 { @@ -23,15 +22,6 @@ IAuthServiceClient authServiceClient m_client = authServiceClient; } - [GenerateSync] - Task INonCachingAccessTokenProvider.ProvisionAccessTokenAsync( - ClaimSet claimSet, - IEnumerable scopes - ) { - var @this = this as INonCachingAccessTokenProvider; - return @this.ProvisionAccessTokenAsync( claimSet.ToClaims(), scopes ); - } - [GenerateSync] async Task INonCachingAccessTokenProvider.ProvisionAccessTokenAsync( IEnumerable claimSet, diff --git a/src/D2L.Security.OAuth2/Provisioning/Default/CachedAccessTokenProvider.cs b/src/D2L.Security.OAuth2/Provisioning/Default/CachedAccessTokenProvider.cs index f579d624..5c3dc3cd 100644 --- a/src/D2L.Security.OAuth2/Provisioning/Default/CachedAccessTokenProvider.cs +++ b/src/D2L.Security.OAuth2/Provisioning/Default/CachedAccessTokenProvider.cs @@ -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 @@ -33,16 +32,6 @@ TimeSpan tokenRefreshGracePeriod m_tokenHandler = new JwtSecurityTokenHandler(); } - [GenerateSync] - async Task IAccessTokenProvider.ProvisionAccessTokenAsync( - ClaimSet claimSet, - IEnumerable scopes, - ICache cache - ) { - var @this = this as IAccessTokenProvider; - return await @this.ProvisionAccessTokenAsync( claimSet.ToClaims(), scopes, cache ).ConfigureAwait( false ); - } - [GenerateSync] async Task IAccessTokenProvider.ProvisionAccessTokenAsync( IEnumerable claims, diff --git a/src/D2L.Security.OAuth2/Provisioning/Default/INonCachingAccessTokenProvider.cs b/src/D2L.Security.OAuth2/Provisioning/Default/INonCachingAccessTokenProvider.cs index 0c7695d0..1bd494a9 100644 --- a/src/D2L.Security.OAuth2/Provisioning/Default/INonCachingAccessTokenProvider.cs +++ b/src/D2L.Security.OAuth2/Provisioning/Default/INonCachingAccessTokenProvider.cs @@ -5,15 +5,7 @@ using D2L.Security.OAuth2.Scopes; namespace D2L.Security.OAuth2.Provisioning.Default { - internal partial interface INonCachingAccessTokenProvider { - - [GenerateSync] - Task ProvisionAccessTokenAsync( - ClaimSet claimSet, - IEnumerable scopes - ); - [GenerateSync] Task ProvisionAccessTokenAsync( IEnumerable claims, diff --git a/src/D2L.Security.OAuth2/Provisioning/IAccessTokenProvider.cs b/src/D2L.Security.OAuth2/Provisioning/IAccessTokenProvider.cs index 188543e1..13981f89 100644 --- a/src/D2L.Security.OAuth2/Provisioning/IAccessTokenProvider.cs +++ b/src/D2L.Security.OAuth2/Provisioning/IAccessTokenProvider.cs @@ -6,29 +6,11 @@ using D2L.Security.OAuth2.Scopes; namespace D2L.Security.OAuth2.Provisioning { - /// /// Provisions access tokens from the auth service /// /// This type is disposable public partial interface IAccessTokenProvider { - - /// - /// Provisions an access token containing the provided claims and scopes. - /// - /// The set of claims to be included in the token. - /// The set of scopes to be included in the token. - /// The provided does not need to - /// check for token expiration or grace period because the - /// will handle it internally. - /// An access token containing an expiry and the provided claims and scopes. - [GenerateSync] - Task ProvisionAccessTokenAsync( - ClaimSet claimSet, - IEnumerable scopes, - ICache cache = null - ); - /// /// Provisions an access token containing the provided claims and scopes. /// diff --git a/test/D2L.Security.OAuth2.IntegrationTests/TestFramework/TestAccessTokenProviderTests.cs b/test/D2L.Security.OAuth2.IntegrationTests/TestFramework/TestAccessTokenProviderTests.cs index 9b9377b7..32d428f4 100644 --- a/test/D2L.Security.OAuth2.IntegrationTests/TestFramework/TestAccessTokenProviderTests.cs +++ b/test/D2L.Security.OAuth2.IntegrationTests/TestFramework/TestAccessTokenProviderTests.cs @@ -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; @@ -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( "*", "*", "*" ) }; diff --git a/test/D2L.Security.OAuth2.UnitTests/Provisioning/CachedAccessTokenProviderTests.cs b/test/D2L.Security.OAuth2.UnitTests/Provisioning/CachedAccessTokenProviderTests.cs index 38378331..fbaa0d0a 100644 --- a/test/D2L.Security.OAuth2.UnitTests/Provisioning/CachedAccessTokenProviderTests.cs +++ b/test/D2L.Security.OAuth2.UnitTests/Provisioning/CachedAccessTokenProviderTests.cs @@ -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 = diff --git a/test/D2L.Security.OAuth2.UnitTests/Provisioning/Default/AccessTokenProviderTests.cs b/test/D2L.Security.OAuth2.UnitTests/Provisioning/Default/AccessTokenProviderTests.cs index 89e38962..c6abc755 100644 --- a/test/D2L.Security.OAuth2.UnitTests/Provisioning/Default/AccessTokenProviderTests.cs +++ b/test/D2L.Security.OAuth2.UnitTests/Provisioning/Default/AccessTokenProviderTests.cs @@ -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[] { } )