sec: add verification for OAuth authorization

This commit is contained in:
nikita 2024-12-26 15:47:38 +03:00
parent 5b7412f20f
commit c75ac60b0b

View File

@ -183,8 +183,18 @@ public class AuthService(ICacheService cache, IAccessToken accessTokenService, I
public Task<TwoFactorAuthenticator> LoginOAuthAsync(CookieOptions cookieOptions, public Task<TwoFactorAuthenticator> LoginOAuthAsync(CookieOptions cookieOptions,
HttpContext context, HttpContext context,
User user, User user,
CancellationToken cancellation = default) => OAuthUser oAuthUser,
LoginAsync(cookieOptions, context, user, cancellation); OAuthProvider provider,
CancellationToken cancellation = default)
{
if (user.OAuthProviders == null || !user.OAuthProviders.TryGetValue(provider, out var value))
throw new SecurityException($"This provider '{Enum.GetName(provider)}' is not linked to the account.");
if (value.Id != oAuthUser.Id)
throw new SecurityException("This account was not linked");
return LoginAsync(cookieOptions, context, user, cancellation);
}
public async Task<TwoFactorAuthenticator> LoginAsync(CookieOptions cookieOptions, public async Task<TwoFactorAuthenticator> LoginAsync(CookieOptions cookieOptions,
HttpContext context, HttpContext context,