-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from EasyAbp/authorizer-accesstoken-cache
Introduce `IAuthorizerAccessTokenCache`
- Loading branch information
Showing
5 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
....OpenPlatform/Infrastructure/ThirdPartyPlatform/AccessToken/AuthorizerAccessTokenCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Caching.Distributed; | ||
using Volo.Abp.Caching; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace EasyAbp.Abp.WeChat.OpenPlatform.Infrastructure.ThirdPartyPlatform.AccessToken; | ||
|
||
public class AuthorizerAccessTokenCache : IAuthorizerAccessTokenCache, ITransientDependency | ||
{ | ||
protected IDistributedCache<string> Cache { get; } | ||
|
||
public AuthorizerAccessTokenCache(IDistributedCache<string> cache) | ||
{ | ||
Cache = cache; | ||
} | ||
|
||
public virtual async Task<string> GetAsync(string componentAppId, string authorizerAppId) | ||
{ | ||
return await Cache.GetAsync(await GetCacheKeyAsync(componentAppId, authorizerAppId)); | ||
} | ||
|
||
public virtual async Task SetAsync(string componentAppId, string authorizerAppId, string accessToken) | ||
{ | ||
await Cache.SetAsync( | ||
await GetCacheKeyAsync(componentAppId, authorizerAppId), | ||
accessToken, | ||
new DistributedCacheEntryOptions | ||
{ | ||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(115) | ||
}); | ||
} | ||
|
||
protected virtual async Task<string> GetCacheKeyAsync(string componentAppId, string authorizerAppId) => | ||
$"AuthorizerAccessToken:{componentAppId}:{authorizerAppId}"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...OpenPlatform/Infrastructure/ThirdPartyPlatform/AccessToken/IAuthorizerAccessTokenCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System.Threading.Tasks; | ||
using JetBrains.Annotations; | ||
|
||
namespace EasyAbp.Abp.WeChat.OpenPlatform.Infrastructure.ThirdPartyPlatform.AccessToken; | ||
|
||
public interface IAuthorizerAccessTokenCache | ||
{ | ||
Task<string> GetAsync([NotNull] string componentAppId, [NotNull] string authorizerAppId); | ||
|
||
Task SetAsync([NotNull] string componentAppId, [NotNull] string authorizerAppId, [NotNull] string accessToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters