File scoped namespaces

This commit is contained in:
Aleh Khantsevich
2025-02-16 11:35:43 +01:00
committed by GitHub
parent c1336428dc
commit d31d8f574e
617 changed files with 32118 additions and 32737 deletions

View File

@@ -7,50 +7,49 @@ using Wino.Core.Domain.Models.Server;
using Wino.Messaging.Server;
using Wino.Server.Core;
namespace Wino.Server.MessageHandlers
namespace Wino.Server.MessageHandlers;
public class AuthenticationHandler : ServerMessageHandler<AuthorizationRequested, TokenInformationEx>
{
public class AuthenticationHandler : ServerMessageHandler<AuthorizationRequested, TokenInformationEx>
private readonly IAuthenticationProvider _authenticationProvider;
public override WinoServerResponse<TokenInformationEx> FailureDefaultResponse(Exception ex)
=> WinoServerResponse<TokenInformationEx>.CreateErrorResponse(ex.Message);
public AuthenticationHandler(IAuthenticationProvider authenticationProvider)
{
private readonly IAuthenticationProvider _authenticationProvider;
_authenticationProvider = authenticationProvider;
}
public override WinoServerResponse<TokenInformationEx> FailureDefaultResponse(Exception ex)
=> WinoServerResponse<TokenInformationEx>.CreateErrorResponse(ex.Message);
protected override async Task<WinoServerResponse<TokenInformationEx>> HandleAsync(AuthorizationRequested message,
CancellationToken cancellationToken = default)
{
var authenticator = _authenticationProvider.GetAuthenticator(message.MailProviderType);
public AuthenticationHandler(IAuthenticationProvider authenticationProvider)
// Some users are having issues with Gmail authentication.
// Their browsers may never launch to complete authentication.
// Offer to copy auth url for them to complete it manually.
// Redirection will occur to the app and the token will be saved.
if (message.ProposeCopyAuthorizationURL && authenticator is IGmailAuthenticator gmailAuthenticator)
{
_authenticationProvider = authenticationProvider;
gmailAuthenticator.ProposeCopyAuthURL = true;
}
protected override async Task<WinoServerResponse<TokenInformationEx>> HandleAsync(AuthorizationRequested message,
CancellationToken cancellationToken = default)
TokenInformationEx generatedToken = null;
if (message.CreatedAccount != null)
{
var authenticator = _authenticationProvider.GetAuthenticator(message.MailProviderType);
// Some users are having issues with Gmail authentication.
// Their browsers may never launch to complete authentication.
// Offer to copy auth url for them to complete it manually.
// Redirection will occur to the app and the token will be saved.
if (message.ProposeCopyAuthorizationURL && authenticator is IGmailAuthenticator gmailAuthenticator)
{
gmailAuthenticator.ProposeCopyAuthURL = true;
}
TokenInformationEx generatedToken = null;
if (message.CreatedAccount != null)
{
generatedToken = await authenticator.GetTokenInformationAsync(message.CreatedAccount);
}
else
{
// Initial authentication request.
// There is no account to get token for.
generatedToken = await authenticator.GenerateTokenInformationAsync(message.CreatedAccount);
}
return WinoServerResponse<TokenInformationEx>.CreateSuccessResponse(generatedToken);
generatedToken = await authenticator.GetTokenInformationAsync(message.CreatedAccount);
}
else
{
// Initial authentication request.
// There is no account to get token for.
generatedToken = await authenticator.GenerateTokenInformationAsync(message.CreatedAccount);
}
return WinoServerResponse<TokenInformationEx>.CreateSuccessResponse(generatedToken);
}
}