Files
Wino-Mail/Wino.Core/Http/MicrosoftTokenProvider.cs

33 lines
1.0 KiB
C#
Raw Permalink Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Kiota.Abstractions.Authentication;
using Wino.Core.Domain.Entities.Shared;
2024-04-18 01:44:37 +02:00
using Wino.Core.Domain.Interfaces;
2025-02-16 11:54:23 +01:00
namespace Wino.Core.Http;
public class MicrosoftTokenProvider : IAccessTokenProvider
2024-04-18 01:44:37 +02:00
{
2025-02-16 11:54:23 +01:00
private readonly MailAccount _account;
private readonly IAuthenticator _authenticator;
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public MicrosoftTokenProvider(MailAccount account, IAuthenticator authenticator)
{
_account = account;
_authenticator = authenticator;
}
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
public AllowedHostsValidator AllowedHostsValidator { get; }
2025-02-16 11:54:23 +01:00
public async Task<string> GetAuthorizationTokenAsync(Uri uri,
Dictionary<string, object> additionalAuthenticationContext = null,
CancellationToken cancellationToken = default)
{
var tokenInfo = await _authenticator.GetTokenInformationAsync(_account);
2024-04-18 01:44:37 +02:00
2025-02-16 11:54:23 +01:00
return tokenInfo.AccessToken;
2024-04-18 01:44:37 +02:00
}
}