Skip to content

Commit 220eb43

Browse files
committed
fix: Display error when a user connected with OIDC token from another account
1 parent b292bdf commit 220eb43

5 files changed

Lines changed: 24 additions & 1 deletion

File tree

assets/locales/en.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ msgstr "The authentication has failed"
482482
msgid "the FranceConnect authentication has failed"
483483
msgstr "The FranceConnect authentication has failed"
484484

485+
msgid "OIDC Domain Mismatch %s %s"
486+
msgstr "To connect to %s, please disconnect first from %s"
487+
485488
msgid "Instance Blocked Login"
486489
msgstr "The Twake was blocked because of too many login attempts"
487490

assets/locales/fr.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ msgstr "L'authentification n'a pu aboutir"
550550
msgid "the FranceConnect authentication has failed"
551551
msgstr "Le compte FranceConnect utilisé ne correspond pas à votre compte Twake."
552552

553+
msgid "OIDC Domain Mismatch %s %s"
554+
msgstr "Pour vous connecter à %s, veuillez d'abord vous déconnecter de %s"
555+
553556
msgid "Instance Blocked Login"
554557
msgstr "Le Twake a été bloqué à cause de trop nombreux essais de connexion"
555558

assets/locales/ru.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ msgstr "Аутентификация не удалась"
533533
msgid "the FranceConnect authentication has failed"
534534
msgstr "Используемый аккаунт FranceConnect не соответствует вашему аккаунту Twake."
535535

536+
msgid "OIDC Domain Mismatch %s %s"
537+
msgstr "Чтобы подключиться к %s, сначала отключитесь от %s"
538+
536539
msgid "Instance Blocked Login"
537540
msgstr "Twake был заблокирован из-за слишком многих попыток входа"
538541

assets/locales/vi.po

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ msgstr "Xác thực không thành công"
484484
msgid "the FranceConnect authentication has failed"
485485
msgstr "Xác thực bằng FranceConnect không thành công"
486486

487+
msgid "OIDC Domain Mismatch %s %s"
488+
msgstr "Để kết nối với %s, vui lòng đăng xuất khỏi %s trước"
489+
487490
msgid "Instance Blocked Login"
488491
msgstr "Twake đã bị khóa do có quá nhiều lần đăng nhập không thành công"
489492

web/oidc/oidc.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ var (
4343
ErrIdentityProvider = errors.New("error from the identity provider")
4444
)
4545

46+
// DomainMismatchError is returned when the user tries to connect to an
47+
// instance but has an active OIDC session for a different instance.
48+
type DomainMismatchError struct {
49+
ExpectedDomain string // The instance the user is trying to access
50+
ActualDomain string // The instance from the OIDC token
51+
}
52+
53+
func (e *DomainMismatchError) Error() string {
54+
return fmt.Sprintf("OIDC Domain Mismatch %s %s", e.ExpectedDomain, e.ActualDomain)
55+
}
56+
4657
// extractSessionID extracts the session ID (sid) from an id_token.
4758
func extractSessionID(idToken string) string {
4859
if idToken == "" {
@@ -1054,7 +1065,7 @@ func checkDomainFromUserInfo(conf *Config, inst *instance.Instance, token string
10541065
}
10551066
if domain != inst.Domain {
10561067
logger.WithNamespace("oidc").Errorf("Invalid domains: %s != %s", domain, inst.Domain)
1057-
return ErrAuthenticationFailed
1068+
return &DomainMismatchError{ExpectedDomain: inst.Domain, ActualDomain: domain}
10581069
}
10591070
return nil
10601071
}

0 commit comments

Comments
 (0)