-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCasTokenService.cs
More file actions
42 lines (38 loc) · 1.56 KB
/
CasTokenService.cs
File metadata and controls
42 lines (38 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Unity.GrantManager.Integrations;
using Unity.Modules.Shared.Integrations;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.Caching;
using Unity.GrantManager.Integrations.Css;
using Volo.Abp.DependencyInjection;
namespace Unity.Payments.Integrations.Cas
{
[IntegrationService]
[ExposeServices(typeof(CasTokenService), typeof(ICasTokenService))]
public class CasTokenService(
IEndpointManagementAppService endpointManagementAppService,
IOptions<CasClientOptions> casClientOptions,
IHttpClientFactory httpClientFactory,
IDistributedCache<TokenValidationResponse, string> chesTokenCache
) : ApplicationService, ICasTokenService
{
private const string OAUTH_PATH = "oauth/token";
private const string CAS_API_KEY = "CasApiKey";
public async Task<string> GetAuthTokenAsync()
{
string caseBaseUrl = await endpointManagementAppService.GetUgmUrlByKeyNameAsync(DynamicUrlKeyNames.PAYMENT_API_BASE);
ClientOptions clientOptions = new ClientOptions
{
Url = $"{caseBaseUrl}/{OAUTH_PATH}",
ClientId = casClientOptions.Value.CasClientId,
ClientSecret = casClientOptions.Value.CasClientSecret,
ApiKey = CAS_API_KEY,
};
TokenService tokenService = new(httpClientFactory, chesTokenCache, Logger);
return await tokenService.GetAuthTokenAsync(clientOptions);
}
}
}