Skip to content

Commit

Permalink
Fixing profile sync for gmail and separating authenticators token sto…
Browse files Browse the repository at this point in the history
…rage.
  • Loading branch information
bkaankose committed Dec 1, 2024
1 parent 0cd1568 commit 678d947
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 30 deletions.
4 changes: 1 addition & 3 deletions Wino.Authentication/GmailAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Wino.Authentication
{
public class GmailAuthenticator : BaseAuthenticator, IGmailAuthenticator
{
private const string FileDataStoreFolder = "WinoGmailStore";

public GmailAuthenticator(IAuthenticatorConfig authConfig) : base(authConfig)
{
}
Expand Down Expand Up @@ -47,7 +45,7 @@ private Task<UserCredential> GetGoogleUserCredentialAsync(MailAccount account)
return GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets()
{
ClientId = ClientId
}, AuthenticatorConfig.GmailScope, account.Id.ToString(), CancellationToken.None, new FileDataStore(FileDataStoreFolder));
}, AuthenticatorConfig.GmailScope, account.Id.ToString(), CancellationToken.None, new FileDataStore(AuthenticatorConfig.GmailTokenStoreIdentifier));
}
}
}
13 changes: 13 additions & 0 deletions Wino.Calendar.ViewModels/CalendarViewModelContainerSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using Wino.Core;

namespace Wino.Calendar.ViewModels
{
public static class CalendarViewModelContainerSetup
{
public static void RegisterCalendarViewModelServices(this IServiceCollection services)
{
services.RegisterCoreServices();
}
}
}
1 change: 1 addition & 0 deletions Wino.Calendar.ViewModels/Wino.Calendar.ViewModels.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<ProjectReference Include="..\Wino.Core.ViewModels\Wino.Core.ViewModels.csproj" />
<ProjectReference Include="..\Wino.Core\Wino.Core.csproj" />
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.csproj" />
<ProjectReference Include="..\Wino.Services\Wino.Services.csproj" />
</ItemGroup>

</Project>
44 changes: 44 additions & 0 deletions Wino.Calendar.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Wino.Calendar.Packaging", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wino.Calendar.ViewModels", "Wino.Calendar.ViewModels\Wino.Calendar.ViewModels.csproj", "{CF850F8C-5042-4376-9CBA-C8F2BB554083}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wino.Services", "Wino.Services\Wino.Services.csproj", "{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wino.Authentication", "Wino.Authentication\Wino.Authentication.csproj", "{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -257,6 +261,46 @@ Global
{CF850F8C-5042-4376-9CBA-C8F2BB554083}.Release|x64.Build.0 = Release|x64
{CF850F8C-5042-4376-9CBA-C8F2BB554083}.Release|x86.ActiveCfg = Release|x86
{CF850F8C-5042-4376-9CBA-C8F2BB554083}.Release|x86.Build.0 = Release|x86
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM.ActiveCfg = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM.Build.0 = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|ARM64.Build.0 = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x64.ActiveCfg = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x64.Build.0 = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x86.ActiveCfg = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Debug|x86.Build.0 = Debug|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|Any CPU.Build.0 = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM.ActiveCfg = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM.Build.0 = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM64.ActiveCfg = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|ARM64.Build.0 = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x64.ActiveCfg = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x64.Build.0 = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x86.ActiveCfg = Release|Any CPU
{BBA49030-7277-48CF-B2FE-3D01CB6B6C81}.Release|x86.Build.0 = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM.ActiveCfg = Debug|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM.Build.0 = Debug|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|ARM64.Build.0 = Debug|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x64.ActiveCfg = Debug|x64
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x64.Build.0 = Debug|x64
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x86.ActiveCfg = Debug|x86
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Debug|x86.Build.0 = Debug|x86
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|Any CPU.Build.0 = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM.ActiveCfg = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM.Build.0 = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM64.ActiveCfg = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|ARM64.Build.0 = Release|Any CPU
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x64.ActiveCfg = Release|x64
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x64.Build.0 = Release|x64
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x86.ActiveCfg = Release|x86
{16A979C2-F308-464F-9B2A-0AF8ED5EDB43}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 3 additions & 2 deletions Wino.Calendar/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
using Wino.Calendar.Activation;
using Wino.Calendar.Services;
using Wino.Calendar.ViewModels;
using Wino.Core;
using Wino.Core.Domain.Interfaces;
using Wino.Core.UWP;
using Wino.Messaging.Client.Connection;
using Wino.Messaging.Server;
using Wino.Services;

namespace Wino.Calendar
{
Expand All @@ -38,7 +38,8 @@ public override IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();

services.RegisterCoreServices();
services.RegisterSharedServices();
services.RegisterCalendarViewModelServices();
services.RegisterCoreUWPServices();
services.RegisterCoreViewModels();

Expand Down
7 changes: 5 additions & 2 deletions Wino.Calendar/Services/CalendarAuthenticatorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ public class CalendarAuthenticatorConfig : IAuthenticatorConfig

public string[] GmailScope => new string[]
{
"https://mail.google.com/",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/calendar.events",
"https://www.googleapis.com/auth/calendar.settings.readonly"
"https://www.googleapis.com/auth/calendar.settings.readonly",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/userinfo.email"
};

public string GmailTokenStoreIdentifier => "WinoCalendarGmailTokenStore";
}
}
8 changes: 4 additions & 4 deletions Wino.Calendar/Wino.Calendar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@
<Project>{53723ae8-7e7e-4d54-adab-0a6033255cc8}</Project>
<Name>Wino.Core.ViewModels</Name>
</ProjectReference>
<ProjectReference Include="..\Wino.Core\Wino.Core.csproj">
<Project>{e6b1632a-8901-41e8-9ddf-6793c7698b0b}</Project>
<Name>Wino.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.csproj">
<Project>{0c307d7e-256f-448c-8265-5622a812fbcc}</Project>
<Name>Wino.Messaging</Name>
</ProjectReference>
<ProjectReference Include="..\Wino.Services\Wino.Services.csproj">
<Project>{bba49030-7277-48cf-b2fe-3d01cb6b6c81}</Project>
<Name>Wino.Services</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
Expand Down
1 change: 1 addition & 0 deletions Wino.Core.Domain/Interfaces/IAuthenticatorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public interface IAuthenticatorConfig
string[] OutlookScope { get; }
string GmailAuthenticatorClientId { get; }
string[] GmailScope { get; }
string GmailTokenStoreIdentifier { get; }
}
}
12 changes: 6 additions & 6 deletions Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Wino.Core.UWP/Dialogs/AccountCreationDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
using Windows.UI.Xaml;
using Wino.Core.Domain.Enums;
using Wino.Core.Domain.Interfaces;
using Wino.Core.UWP;
using Wino.Messaging.UI;
Expand All @@ -18,6 +20,11 @@ public AccountCreationDialog()
WeakReferenceMessenger.Default.Register(this);
}

public override void OnStateChanged(AccountCreationDialogState state)
{
var tt = VisualStateManager.GoToState(this, state.ToString(), true);
}

public async void Receive(CopyAuthURLRequested message)
{
copyClipboardURL = message.AuthURL;
Expand Down
10 changes: 9 additions & 1 deletion Wino.Core.UWP/Dialogs/BaseAccountCreationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public AccountCreationDialogState State

public CancellationTokenSource CancellationTokenSource { get; private set; }

public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle));
public static readonly DependencyProperty StateProperty = DependencyProperty.Register(nameof(State), typeof(AccountCreationDialogState), typeof(BaseAccountCreationDialog), new PropertyMetadata(AccountCreationDialogState.Idle, OnStateChanged));

private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dialog = d as BaseAccountCreationDialog;
dialog.OnStateChanged((AccountCreationDialogState)e.NewValue);
}

public abstract void OnStateChanged(AccountCreationDialogState state);

// Prevent users from dismissing it by ESC key.
public void DialogClosing(ContentDialog sender, ContentDialogClosingEventArgs args)
Expand Down
2 changes: 0 additions & 2 deletions Wino.Core.UWP/WinoApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public abstract class WinoApplication : Application
protected IThemeService ThemeService { get; }
protected IDatabaseService DatabaseService { get; }
protected ITranslationService TranslationService { get; }
protected IMailDialogService DialogService { get; }

// Order matters.
private List<IInitializeAsync> initializeServices => new List<IInitializeAsync>()
Expand Down Expand Up @@ -69,7 +68,6 @@ protected WinoApplication()
ThemeService = Services.GetService<IThemeService>();
DatabaseService = Services.GetService<IDatabaseService>();
TranslationService = Services.GetService<ITranslationService>();
DialogService = Services.GetService<IMailDialogService>();

// Make sure the paths are setup on app start.
AppConfiguration.ApplicationDataFolderPath = ApplicationData.Current.LocalFolder.Path;
Expand Down
14 changes: 6 additions & 8 deletions Wino.Core/Synchronizers/GmailSynchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class GmailSynchronizer : WinoSynchronizer<IClientServiceRequest, Message
private readonly GmailService _gmailService;
private readonly PeopleServiceService _peopleService;

private readonly IGmailAuthenticator _authenticator;
private readonly IGmailChangeProcessor _gmailChangeProcessor;
private readonly ILogger _logger = Log.ForContext<GmailSynchronizer>();

Expand All @@ -68,9 +67,6 @@ public GmailSynchronizer(MailAccount account,

_gmailService = new GmailService(initializer);
_peopleService = new PeopleServiceService(initializer);


_authenticator = authenticator;
_gmailChangeProcessor = gmailChangeProcessor;
}

Expand All @@ -79,14 +75,14 @@ public GmailSynchronizer(MailAccount account,
public override async Task<ProfileInformation> GetProfileInformationAsync()
{
var profileRequest = _peopleService.People.Get("people/me");
profileRequest.PersonFields = "names,photos";
profileRequest.PersonFields = "names,photos,emailAddresses";

string senderName = string.Empty, base64ProfilePicture = string.Empty, address = string.Empty;

var gmailUserData = _gmailService.Users.GetProfile("me");
var gmailProfile = await gmailUserData.ExecuteAsync();
//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;
Expand All @@ -98,6 +94,8 @@ public override async Task<ProfileInformation> GetProfileInformationAsync()
base64ProfilePicture = await GetProfilePictureBase64EncodedAsync(profilePicture).ConfigureAwait(false);
}

address = userProfile.EmailAddresses.FirstOrDefault().Value;

return new ProfileInformation(senderName, base64ProfilePicture, address);
}

Expand Down
6 changes: 4 additions & 2 deletions Wino.Mail/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ public async void Receive(NewSynchronizationRequested message)
}
catch (WinoServerException serverException)
{
DialogService.InfoBarMessage(Translator.Info_SyncFailedTitle, serverException.Message, InfoBarMessageType.Error);
var dialogService = Services.GetService<IMailDialogService>();

dialogService.InfoBarMessage(Translator.Info_SyncFailedTitle, serverException.Message, InfoBarMessageType.Error);
}
}

Expand All @@ -260,7 +262,7 @@ protected override async void OnApplicationCloseRequested(object sender, SystemN
// Starting the server is fine, but check if server termination behavior is set to terminate.
// This state will kill the server once the app is terminated.

isGoToAppPreferencesRequested = await DialogService.ShowWinoCustomMessageDialogAsync(Translator.AppCloseBackgroundSynchronizationWarningTitle,
isGoToAppPreferencesRequested = await dialogService.ShowWinoCustomMessageDialogAsync(Translator.AppCloseBackgroundSynchronizationWarningTitle,
$"{Translator.AppCloseTerminateBehaviorWarningMessageFirstLine}\n{Translator.AppCloseTerminateBehaviorWarningMessageSecondLine}\n\n{Translator.AppCloseTerminateBehaviorWarningMessageThirdLine}",
Translator.Buttons_Yes,
WinoCustomMessageDialogIcon.Warning,
Expand Down
2 changes: 2 additions & 0 deletions Wino.Mail/Services/MailAuthenticatorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ public class MailAuthenticatorConfiguration : IAuthenticatorConfig
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/gmail.labels"
};

public string GmailTokenStoreIdentifier => "WinoMailGmailTokenStore";
}
}

0 comments on commit 678d947

Please sign in to comment.