-
Notifications
You must be signed in to change notification settings - Fork 16
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
Move caching stuff off the IAccessTokenProvider API into the factory #373
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using System.Net.Http; | ||
using D2L.Security.OAuth2.Caching; | ||
using D2L.Security.OAuth2.Keys; | ||
using D2L.Security.OAuth2.Provisioning.Default; | ||
|
||
|
@@ -18,18 +19,34 @@ public static IAccessTokenProvider Create( | |
ITokenSigner tokenSigner, | ||
HttpClient httpClient, | ||
Uri authEndpoint, | ||
TimeSpan tokenRefreshGracePeriod | ||
TimeSpan tokenRefreshGracePeriod, | ||
IAccessTokenProvider inner = null, | ||
ICache cache = null | ||
) { | ||
if( inner != null && cache == null ) { | ||
throw new InvalidOperationException( "If you provide an inner you need to also provide its cache" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here is that this factory is either for wrapping your IAccessTokenProvider in our caching layer (for which you provide an ICache for us to use) or for using our jwt-bearer-grant based impl with or without caching. The reason I'm doing this is I want to implement an IamGrant IAccessTokenProvider impl. I want to do that inside the LMS because I'd really like to use the LMS Lambda framework. It would make sense to implement it in this library, and I mean you could at least define the input/output here, but meh. |
||
} | ||
|
||
IAuthServiceClient authServiceClient = new AuthServiceClient( | ||
httpClient, | ||
authEndpoint | ||
); | ||
if( inner == null ) { | ||
IAuthServiceClient authServiceClient = new AuthServiceClient( | ||
httpClient, | ||
authEndpoint | ||
); | ||
|
||
inner = new AccessTokenProvider( tokenSigner, authServiceClient ); | ||
} | ||
|
||
INonCachingAccessTokenProvider accessTokenProvider = | ||
new AccessTokenProvider( tokenSigner, authServiceClient ); | ||
|
||
return new CachedAccessTokenProvider( accessTokenProvider, authEndpoint, tokenRefreshGracePeriod ); | ||
if( cache != null ) { | ||
return inner; | ||
} | ||
|
||
return new CachedAccessTokenProvider( | ||
cache, | ||
inner, | ||
authEndpoint, | ||
tokenRefreshGracePeriod | ||
); | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using D2L.CodeStyle.Annotations; | ||
using D2L.Security.OAuth2.Caching; | ||
using D2L.Security.OAuth2.Scopes; | ||
|
||
namespace D2L.Security.OAuth2.Provisioning { | ||
|
@@ -16,15 +15,13 @@ public partial interface IAccessTokenProvider { | |
/// </summary> | ||
/// <param name="claims">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( | ||
IEnumerable<Claim> claims, | ||
IEnumerable<Scope> scopes, | ||
ICache cache = null | ||
IEnumerable<Scope> scopes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consolidating on one interface, equivalent to the old non-caching one, and taking the cache inside the factory+constructor. The LMS cache is instantiated each call but it can be safely cached. |
||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests