feat: доделал MS Auth для фронта
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user