Abstraction of authenticators. Reworked Gmail authentication.

This commit is contained in:
Burak Kaan Köse
2024-11-20 01:45:48 +01:00
parent 8367efa174
commit 7fad15524f
44 changed files with 354 additions and 605 deletions

View File

@@ -119,6 +119,11 @@ namespace Wino.Core.Synchronizers
{
Account.SenderName = profileInformation.SenderName;
Account.Base64ProfilePictureData = profileInformation.Base64ProfilePictureData;
if (!string.IsNullOrEmpty(profileInformation.AccountAddress))
{
Account.Address = profileInformation.AccountAddress;
}
}
return profileInformation;

View File

@@ -46,15 +46,15 @@ namespace Wino.Core.Synchronizers.Mail
private readonly GmailService _gmailService;
private readonly PeopleServiceService _peopleService;
private readonly IAuthenticator _authenticator;
private readonly IGmailAuthenticator _authenticator;
private readonly IGmailChangeProcessor _gmailChangeProcessor;
private readonly ILogger _logger = Log.ForContext<GmailSynchronizer>();
public GmailSynchronizer(MailAccount account,
IAuthenticator authenticator,
IGmailAuthenticator authenticator,
IGmailChangeProcessor gmailChangeProcessor) : base(account)
{
var messageHandler = new GmailClientMessageHandler(() => _authenticator.GetTokenAsync(Account));
var messageHandler = new GmailClientMessageHandler(authenticator, account);
var initializer = new BaseClientService.Initializer()
{
@@ -77,8 +77,12 @@ namespace Wino.Core.Synchronizers.Mail
var profileRequest = _peopleService.People.Get("people/me");
profileRequest.PersonFields = "names,photos";
string senderName = string.Empty, base64ProfilePicture = string.Empty;
string senderName = string.Empty, base64ProfilePicture = string.Empty, address = string.Empty;
var gmailUserData = _gmailService.Users.GetProfile("me");
var gmailProfile = await gmailUserData.ExecuteAsync();
address = gmailProfile.EmailAddress;
var userProfile = await profileRequest.ExecuteAsync();
senderName = userProfile.Names?.FirstOrDefault()?.DisplayName ?? Account.SenderName;
@@ -90,7 +94,7 @@ namespace Wino.Core.Synchronizers.Mail
base64ProfilePicture = await GetProfilePictureBase64EncodedAsync(profilePicture).ConfigureAwait(false);
}
return new ProfileInformation(senderName, base64ProfilePicture);
return new ProfileInformation(senderName, base64ProfilePicture, address);
}
protected override async Task SynchronizeAliasesAsync()

View File

@@ -533,20 +533,20 @@ namespace Wino.Core.Synchronizers.Mail
/// <summary>
/// Get the user's display name.
/// </summary>
/// <returns>Display name of the user.</returns>
private async Task<string> GetSenderNameAsync()
/// <returns>Display name and address of the user.</returns>
private async Task<Tuple<string, string>> GetDisplayNameAndAddressAsync()
{
var userInfo = await _graphClient.Me.GetAsync();
return userInfo.DisplayName;
return new Tuple<string, string>(userInfo.DisplayName, userInfo.Mail);
}
public override async Task<ProfileInformation> GetProfileInformationAsync()
{
var profilePictureData = await GetUserProfilePictureAsync().ConfigureAwait(false);
var senderName = await GetSenderNameAsync().ConfigureAwait(false);
var displayNameAndAddress = await GetDisplayNameAndAddressAsync().ConfigureAwait(false);
return new ProfileInformation(senderName, profilePictureData);
return new ProfileInformation(displayNameAndAddress.Item1, profilePictureData, displayNameAndAddress.Item2);
}
/// <summary>