feat: доделал MS Auth для фронта

This commit is contained in:
2026-05-10 21:57:19 +03:00
parent 3af1932480
commit 32ca5963c8
7 changed files with 163 additions and 8 deletions
@@ -30,16 +30,26 @@ public class AuthService : IAuthService
_gamification = gamification;
}
public async Task<AuthResult> LoginWithMicrosoftAsync(string authorizationCode)
public async Task<AuthResult> LoginWithMicrosoftAsync(string authorizationCode, string? redirectUri = null)
{
var tenantId = _config["AzureAd:TenantId"];
var clientId = _config["AzureAd:ClientId"];
var clientSecret = _config["AzureAd:ClientSecret"];
var instance = _config["AzureAd:Instance"] ?? "https://login.microsoftonline.com/";
if (string.IsNullOrWhiteSpace(tenantId) || string.IsNullOrWhiteSpace(clientId) || string.IsNullOrWhiteSpace(clientSecret))
throw new UnauthorizedException("Microsoft authentication is not configured (AzureAd:TenantId/ClientId/ClientSecret).");
var effectiveRedirectUri = redirectUri
?? _config["AzureAd:RedirectUri"]
?? "http://localhost:5173/auth/callback";
var authority = $"{instance.TrimEnd('/')}/{tenantId}";
var app = ConfidentialClientApplicationBuilder.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri($"https://login.microsoftonline.com/{tenantId}"))
.WithRedirectUri(_config["AzureAd:RedirectUri"] ?? "http://localhost:5173/auth/callback")
.WithAuthority(new Uri(authority))
.WithRedirectUri(effectiveRedirectUri)
.Build();
AuthenticationResult result;