@@ -1,9 +1,9 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Services;
|
||||
|
||||
namespace Wino.Core.Authenticators
|
||||
namespace Wino.Core.Authenticators.Base
|
||||
{
|
||||
public abstract class BaseAuthenticator
|
||||
{
|
||||
21
Wino.Core/Authenticators/Base/GmailAuthenticatorBase.cs
Normal file
21
Wino.Core/Authenticators/Base/GmailAuthenticatorBase.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Services;
|
||||
|
||||
namespace Wino.Core.Authenticators.Base
|
||||
{
|
||||
public abstract class GmailAuthenticatorBase : BaseAuthenticator, IGmailAuthenticator
|
||||
{
|
||||
protected GmailAuthenticatorBase(ITokenService tokenService) : base(tokenService)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract string ClientId { get; }
|
||||
public bool ProposeCopyAuthURL { get; set; }
|
||||
|
||||
public abstract Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken);
|
||||
|
||||
public abstract Task<TokenInformation> GetTokenAsync(MailAccount account);
|
||||
}
|
||||
}
|
||||
20
Wino.Core/Authenticators/Base/OutlookAuthenticatorBase.cs
Normal file
20
Wino.Core/Authenticators/Base/OutlookAuthenticatorBase.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Services;
|
||||
|
||||
namespace Wino.Core.Authenticators.Base
|
||||
{
|
||||
public abstract class OutlookAuthenticatorBase : BaseAuthenticator, IOutlookAuthenticator
|
||||
{
|
||||
protected OutlookAuthenticatorBase(ITokenService tokenService) : base(tokenService)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract string ClientId { get; }
|
||||
|
||||
public abstract Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken);
|
||||
|
||||
public abstract Task<TokenInformation> GetTokenAsync(MailAccount account);
|
||||
}
|
||||
}
|
||||
30
Wino.Core/Authenticators/Calendar/OutlookAuthenticator.cs
Normal file
30
Wino.Core/Authenticators/Calendar/OutlookAuthenticator.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Wino.Core.Authenticators.Base;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Services;
|
||||
|
||||
namespace Wino.Core.Authenticators.Calendar
|
||||
{
|
||||
public class OutlookAuthenticator : OutlookAuthenticatorBase
|
||||
{
|
||||
public OutlookAuthenticator(ITokenService tokenService) : base(tokenService)
|
||||
{
|
||||
}
|
||||
|
||||
public override string ClientId => throw new NotImplementedException();
|
||||
|
||||
public override MailProviderType ProviderType => MailProviderType.Outlook;
|
||||
|
||||
public override Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override Task<TokenInformation> GetTokenAsync(MailAccount account)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,9 @@ using System.Text;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Wino.Core.Authenticators.Base;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
@@ -14,11 +15,11 @@ using Wino.Core.Domain.Models.Authorization;
|
||||
using Wino.Core.Services;
|
||||
using Wino.Messaging.UI;
|
||||
|
||||
namespace Wino.Core.Authenticators
|
||||
namespace Wino.Core.Authenticators.Mail
|
||||
{
|
||||
public class GmailAuthenticator : BaseAuthenticator, IGmailAuthenticator
|
||||
public class GmailAuthenticator : GmailAuthenticatorBase
|
||||
{
|
||||
public string ClientId { get; } = "973025879644-s7b4ur9p3rlgop6a22u7iuptdc0brnrn.apps.googleusercontent.com";
|
||||
public override string ClientId { get; } = "973025879644-s7b4ur9p3rlgop6a22u7iuptdc0brnrn.apps.googleusercontent.com";
|
||||
|
||||
private const string TokenEndpoint = "https://www.googleapis.com/oauth2/v4/token";
|
||||
private const string RefreshTokenEndpoint = "https://oauth2.googleapis.com/token";
|
||||
@@ -26,8 +27,6 @@ namespace Wino.Core.Authenticators
|
||||
|
||||
public override MailProviderType ProviderType => MailProviderType.Gmail;
|
||||
|
||||
public bool ProposeCopyAuthURL { get; set; }
|
||||
|
||||
private readonly INativeAppService _nativeAppService;
|
||||
|
||||
public GmailAuthenticator(ITokenService tokenService, INativeAppService nativeAppService) : base(tokenService)
|
||||
@@ -95,7 +94,7 @@ namespace Wino.Core.Authenticators
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<TokenInformation> GetTokenAsync(MailAccount account)
|
||||
public async override Task<TokenInformation> GetTokenAsync(MailAccount account)
|
||||
{
|
||||
var cachedToken = await TokenService.GetTokenInformationAsync(account.Id)
|
||||
?? throw new AuthenticationAttentionException(account);
|
||||
@@ -117,7 +116,7 @@ namespace Wino.Core.Authenticators
|
||||
}
|
||||
|
||||
|
||||
public async Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken)
|
||||
public async override Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken)
|
||||
{
|
||||
var authRequest = _nativeAppService.GetGoogleAuthorizationRequest();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Services;
|
||||
|
||||
namespace Wino.Core.Authenticators
|
||||
namespace Wino.Core.Authenticators.Mail
|
||||
{
|
||||
public class Office365Authenticator : OutlookAuthenticator
|
||||
{
|
||||
@@ -4,21 +4,22 @@ using System.Threading.Tasks;
|
||||
using Microsoft.Identity.Client;
|
||||
using Microsoft.Identity.Client.Broker;
|
||||
using Microsoft.Identity.Client.Extensions.Msal;
|
||||
using Wino.Core.Authenticators.Base;
|
||||
using Wino.Core.Domain;
|
||||
using Wino.Core.Domain.Entities;
|
||||
using Wino.Core.Domain.Entities.Shared;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Exceptions;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Extensions;
|
||||
using Wino.Core.Services;
|
||||
|
||||
namespace Wino.Core.Authenticators
|
||||
namespace Wino.Core.Authenticators.Mail
|
||||
{
|
||||
/// <summary>
|
||||
/// Authenticator for Outlook provider.
|
||||
/// Authenticator for Outlook Mail provider.
|
||||
/// Token cache is managed by MSAL, not by Wino.
|
||||
/// </summary>
|
||||
public class OutlookAuthenticator : BaseAuthenticator, IOutlookAuthenticator
|
||||
public class OutlookAuthenticator : OutlookAuthenticatorBase
|
||||
{
|
||||
private const string TokenCacheFileName = "OutlookCache.bin";
|
||||
private bool isTokenCacheAttached = false;
|
||||
@@ -26,7 +27,7 @@ namespace Wino.Core.Authenticators
|
||||
// Outlook
|
||||
private const string Authority = "https://login.microsoftonline.com/common";
|
||||
|
||||
public string ClientId { get; } = "b19c2035-d740-49ff-b297-de6ec561b208";
|
||||
public override string ClientId { get; } = "b19c2035-d740-49ff-b297-de6ec561b208";
|
||||
|
||||
private readonly string[] MailScope =
|
||||
[
|
||||
@@ -67,7 +68,7 @@ namespace Wino.Core.Authenticators
|
||||
_publicClientApplication = outlookAppBuilder.Build();
|
||||
}
|
||||
|
||||
public async Task<TokenInformation> GetTokenAsync(MailAccount account)
|
||||
public override async Task<TokenInformation> GetTokenAsync(MailAccount account)
|
||||
{
|
||||
if (!isTokenCacheAttached)
|
||||
{
|
||||
@@ -101,7 +102,7 @@ namespace Wino.Core.Authenticators
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken)
|
||||
public override async Task<TokenInformation> GenerateTokenAsync(MailAccount account, bool saveToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
Reference in New Issue
Block a user