Skip to content
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

Fix HybridAccessTokenProvider #55

Merged
merged 1 commit into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>2.0.0-rc.8</Version>
<Version>2.0.0-rc.9</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using EasyAbp.Abp.WeChat.Common.Infrastructure.Options;
using EasyAbp.Abp.WeChat.OpenPlatform.ThirdPartyPlatform.ApiRequests;
using EasyAbp.Abp.WeChat.OpenPlatform.ThirdPartyPlatform.AuthorizerRefreshToken;
using EasyAbp.Abp.WeChat.OpenPlatform.ThirdPartyPlatform.ComponentAccessToken;
using EasyAbp.Abp.WeChat.OpenPlatform.ThirdPartyPlatform.Models;
using EasyAbp.Abp.WeChat.OpenPlatform.ThirdPartyPlatform.Options;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -24,7 +23,6 @@ public class HybridAccessTokenProvider : IAccessTokenProvider, ITransientDepende
private readonly ICurrentWeChatThirdPartyPlatform _currentWeChatThirdPartyPlatform;
private readonly IAbpWeChatOptionsProvider<AbpWeChatThirdPartyPlatformOptions> _optionsProvider;
private readonly IAuthorizerRefreshTokenStore _authorizerRefreshTokenStore;
private readonly IComponentAccessTokenProvider _componentAccessTokenProvider;
private readonly IWeChatThirdPartyPlatformApiRequester _weChatThirdPartyPlatformApiRequester;

public HybridAccessTokenProvider(
Expand All @@ -33,15 +31,13 @@ public class HybridAccessTokenProvider : IAccessTokenProvider, ITransientDepende
ICurrentWeChatThirdPartyPlatform currentWeChatThirdPartyPlatform,
IAbpWeChatOptionsProvider<AbpWeChatThirdPartyPlatformOptions> optionsProvider,
IAuthorizerRefreshTokenStore authorizerRefreshTokenStore,
IComponentAccessTokenProvider componentAccessTokenProvider,
IWeChatThirdPartyPlatformApiRequester weChatThirdPartyPlatformApiRequester)
{
_serviceProvider = serviceProvider;
_cache = cache;
_currentWeChatThirdPartyPlatform = currentWeChatThirdPartyPlatform;
_optionsProvider = optionsProvider;
_authorizerRefreshTokenStore = authorizerRefreshTokenStore;
_componentAccessTokenProvider = componentAccessTokenProvider;
_weChatThirdPartyPlatformApiRequester = weChatThirdPartyPlatformApiRequester;
}

Expand Down Expand Up @@ -77,10 +73,8 @@ public virtual async Task<string> GetAsync(string appId, string appSecret)
{
const string authorizerTokenApiUrl = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token";

var url = await AppendComponentAccessTokenAsync(authorizerTokenApiUrl, options);

var response = await _weChatThirdPartyPlatformApiRequester.RequestAsync<AuthorizerTokenResponse>(
url, HttpMethod.Post, new AuthorizerTokenRequest
authorizerTokenApiUrl, HttpMethod.Post, new AuthorizerTokenRequest
{
ComponentAppId = options.AppId,
AuthorizerAppId = appId,
Expand All @@ -95,12 +89,4 @@ await _authorizerRefreshTokenStore.GetOrNullAsync(options.AppId, appId)

return response.AuthorizerAccessToken;
}

protected virtual async Task<string> AppendComponentAccessTokenAsync(
string url, AbpWeChatThirdPartyPlatformOptions options)
{
var token = await _componentAccessTokenProvider.GetAsync(options.AppId, options.AppSecret);

return url.EnsureEndsWith('?') + $"component_access_token={token}";
}
}