mirror of
https://github.com/VibedByKaKi/forgejo-11-secure.git
synced 2026-10-14 14:28:07 +02:00
- Currently during external login (such as OAuth2), if the user is enrolled into Webauthn and not enrolled into TOTP then no 2FA is being done during external login and when account linking is set to `auto` then also during automatic linking. This results in bypassing the 2FA of the user. - Create a new unified function that checks if the user is enrolled into 2FA and use this when necessary. Rename the old `HasTwoFactorByUID` function to `HasTOTPByUID` which is a more appropiate naming. (cherry picked from commit df5d65682737fee8e215e9f7dc6b369bba3bf313) Conflicts: the original commit was trimmed down to be fit for backport
21 lines
486 B
Go
21 lines
486 B
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// HasTwoFactorByUID returns true if the user has TOTP or WebAuthn enabled for
|
|
// their account.
|
|
func HasTwoFactorByUID(ctx context.Context, userID int64) (bool, error) {
|
|
hasTOTP, err := HasTOTPByUID(ctx, userID)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if hasTOTP {
|
|
return true, nil
|
|
}
|
|
|
|
return HasWebAuthnRegistrationsByUID(ctx, userID)
|
|
}
|