diff --git a/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IOAuth2AuthorizationService.cs b/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IOAuth2AuthorizationService.cs new file mode 100644 index 0000000..1e9f6cc --- /dev/null +++ b/src/core/DigitalData.MessagingService.Application/Common/Interfaces/IOAuth2AuthorizationService.cs @@ -0,0 +1,35 @@ +#if NET +using DigitalData.MessagingService.Domain.Entities; + +namespace DigitalData.MessagingService.Application.Common.Interfaces; + +/// +/// Manages the OAuth2 authorization code flow for providers that require +/// user-delegated access (e.g. Google). Generates authorization URLs and +/// exchanges authorization codes for refresh tokens. +/// +public interface IOAuth2AuthorizationService +{ + /// + /// Builds the authorization URL to redirect the user to for consent. + /// + /// The email account to authorize. + /// The callback URI registered with the OAuth2 provider. + /// The full authorization URL. + string GetAuthorizationUrl(EmailAccount account, string redirectUri); + + /// + /// Exchanges an authorization code for tokens and returns the refresh token. + /// + /// The email account being authorized. + /// The authorization code received from the provider callback. + /// The same redirect URI used in . + /// Cancellation token. + /// The refresh token to be stored on the account. + Task ExchangeCodeForRefreshTokenAsync( + EmailAccount account, + string code, + string redirectUri, + CancellationToken cancellationToken = default); +} +#endif diff --git a/src/core/DigitalData.MessagingService.Application/EmailAccounts/Commands/UpdateAccountOAuth2RefreshTokenCommand.cs b/src/core/DigitalData.MessagingService.Application/EmailAccounts/Commands/UpdateAccountOAuth2RefreshTokenCommand.cs new file mode 100644 index 0000000..e69de29