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;
|
2024-11-10 23:28:25 +01:00
|
|
|
|
using Wino.Core.Domain.Entities.Shared;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Wino.Core.Http
|
|
|
|
|
|
{
|
|
|
|
|
|
public class MicrosoftTokenProvider : IAccessTokenProvider
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly MailAccount _account;
|
|
|
|
|
|
private readonly IAuthenticator _authenticator;
|
|
|
|
|
|
|
|
|
|
|
|
public MicrosoftTokenProvider(MailAccount account, IAuthenticator authenticator)
|
|
|
|
|
|
{
|
|
|
|
|
|
_account = account;
|
|
|
|
|
|
_authenticator = authenticator;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public AllowedHostsValidator AllowedHostsValidator { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<string> GetAuthorizationTokenAsync(Uri uri,
|
2024-11-20 01:45:48 +01:00
|
|
|
|
Dictionary<string, object> additionalAuthenticationContext = null,
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2024-11-20 01:45:48 +01:00
|
|
|
|
var tokenInfo = await _authenticator.GetTokenInformationAsync(_account);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2024-11-20 01:45:48 +01:00
|
|
|
|
return tokenInfo.AccessToken;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|