Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pkg/server/errorpage/errorcodes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package errorpage

import "github.com/openshift/oauth-server/pkg/userregistry/identitymapper"
import (
"github.com/openshift/oauth-server/pkg/server/locales"
"github.com/openshift/oauth-server/pkg/userregistry/identitymapper"
)

const (
// error occurred attempting to claim a user
Expand Down Expand Up @@ -28,14 +31,14 @@ func AuthenticationErrorCode(err error) string {

// AuthenticationErrorMessage returns an error message for the given authentication error code.
// If the error code is not recognized, a generic error message is returned.
func AuthenticationErrorMessage(code string) string {
func AuthenticationErrorMessage(code string, locale locales.Localization) string {
switch code {
case errorCodeClaim:
return "Could not create user."
return locale["CouldNotCreateUser"]
case errorCodeLookup:
return "Could not find user."
return locale["CouldNotFindUser"]
default:
return "An authentication error occurred."
return locale["AnAuthenticationErrorOccurred"]
}
}

Expand All @@ -47,6 +50,6 @@ func GrantErrorCode(err error) string {

// GrantErrorMessage returns an error message for the given grant error code.
// If the error is not recognized, a generic error message is returned.
func GrantErrorMessage(code string) string {
return "A grant error occurred."
func GrantErrorMessage(code string, locale locales.Localization) string {
return locale["GrantErrorOccurred"]
}
7 changes: 5 additions & 2 deletions pkg/server/errorpage/errorpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func (p *ErrorPage) AuthenticationError(err error, w http.ResponseWriter, req *h
if !httprequest.PrefersHTML(req) {
return false, err
}
locale := locales.GetLocale(req.Header.Get("Accept-Language"))

errorData := ErrorData{}
errorData.ErrorCode = AuthenticationErrorCode(err)
errorData.Error = AuthenticationErrorMessage(errorData.ErrorCode)
errorData.Error = AuthenticationErrorMessage(errorData.ErrorCode, locale)

p.render.Render(errorData, w, req)
return true, nil
Expand All @@ -46,9 +47,11 @@ func (p *ErrorPage) GrantError(err error, w http.ResponseWriter, req *http.Reque
return false, err
}

locale := locales.GetLocale(req.Header.Get("Accept-Language"))

errorData := ErrorData{}
errorData.ErrorCode = GrantErrorCode(err)
errorData.Error = GrantErrorMessage(errorData.ErrorCode)
errorData.Error = GrantErrorMessage(errorData.ErrorCode, locale)

p.render.Render(errorData, w, req)
return true, nil
Expand Down
24 changes: 24 additions & 0 deletions pkg/server/locales/locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ var locale_en = Localization{
"LoginIsRequiredPleaseTryAgain": "Login is required. Please try again.",
"CouldNotCheckCSRFTokenPleaseTryAgain": "Could not check CSRF token. Please try again.",
"InvalidLoginOrPasswordPleaseTryAgain": "Invalid login or password. Please try again.",
"CouldNotCreateUser": "Could not create user.",
"CouldNotFindUser": "Could not find user.",
"AnAuthenticationErrorOccurred": "An authentication error occurred.",
"GrantErrorOccurred": "A grant error occurred.",
}

var locale_es = Localization{
Expand All @@ -69,6 +73,10 @@ var locale_es = Localization{
"LoginIsRequiredPleaseTryAgain": "Se requiere iniciar sesión. Por favor, inténtalo de nuevo.",
"CouldNotCheckCSRFTokenPleaseTryAgain": "No se pudo verificar el token CSRF. Por favor, inténtalo de nuevo.",
"InvalidLoginOrPasswordPleaseTryAgain": "Usuario o contraseña inválidos. Por favor, inténtalo de nuevo.",
"CouldNotCreateUser": "No se pudo crear el usuario.",
"CouldNotFindUser": "No se pudo encontrar el usuario.",
"AnAuthenticationErrorOccurred": "Se produjo un error de autenticación.",
"GrantErrorOccurred": "Se produjo un error de concesión.",
}

var locale_fr = Localization{
Expand All @@ -82,6 +90,10 @@ var locale_fr = Localization{
"LoginIsRequiredPleaseTryAgain": "La connexion est requise. Veuillez réessayer.",
"CouldNotCheckCSRFTokenPleaseTryAgain": "Impossible de vérifier le jeton CSRF. Veuillez réessayer.",
"InvalidLoginOrPasswordPleaseTryAgain": "Identifiant ou mot de passe invalide. Veuillez réessayer.",
"CouldNotCreateUser": "Impossible de créer l'utilisateur.",
"CouldNotFindUser": "Impossible de trouver l'utilisateur.",
"AnAuthenticationErrorOccurred": "Une erreur d'authentification s'est produite.",
"GrantErrorOccurred": "Une erreur de concession s'est produite.",
}

var locale_zh = Localization{
Expand All @@ -95,6 +107,10 @@ var locale_zh = Localization{
"LoginIsRequiredPleaseTryAgain": "需要登录。请再次尝试。",
"CouldNotCheckCSRFTokenPleaseTryAgain": "无法检查 CSRF 令牌。请重试。",
"InvalidLoginOrPasswordPleaseTryAgain": "无效的登录或密码。请再次尝试。",
"CouldNotCreateUser": "无法创建用户。",
"CouldNotFindUser": "无法找到用户。",
"AnAuthenticationErrorOccurred": "发生身份验证错误。",
"GrantErrorOccurred": "发生授权错误。",
}

var locale_ja = Localization{
Expand All @@ -108,6 +124,10 @@ var locale_ja = Localization{
"LoginIsRequiredPleaseTryAgain": "ログインが必要です。もう一度やり直してください。",
"CouldNotCheckCSRFTokenPleaseTryAgain": "CSRF トークンを確認できませんでした。もう一度やり直してください。",
"InvalidLoginOrPasswordPleaseTryAgain": "無効なログインまたはパスワードです。もう一度やり直してください。",
"CouldNotCreateUser": "ユーザーを作成できませんでした。",
"CouldNotFindUser": "ユーザーが見つかりませんでした。",
"AnAuthenticationErrorOccurred": "認証エラーが発生しました。",
"GrantErrorOccurred": "許可エラーが発生しました。",
}

var locale_ko = Localization{
Expand All @@ -121,4 +141,8 @@ var locale_ko = Localization{
"LoginIsRequiredPleaseTryAgain": "로그인이 필요합니다. 다시 시도하십시오.",
"CouldNotCheckCSRFTokenPleaseTryAgain": "CSRF 토큰을 확인할 수 없습니다. 다시 시도하십시오.",
"InvalidLoginOrPasswordPleaseTryAgain": "로그인 또는 비밀번호가 잘못되었습니다. 다시 시도하십시오",
"CouldNotCreateUser": "사용자를 만들 수 없습니다.",
"CouldNotFindUser": "사용자를 찾을 수 없습니다.",
"AnAuthenticationErrorOccurred": "인증 오류가 발생했습니다.",
"GrantErrorOccurred": "권한 부여 오류가 발생했습니다.",
}
2 changes: 1 addition & 1 deletion pkg/server/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (l *Login) handleLoginForm(w http.ResponseWriter, req *http.Request) {
if msg, hasMsg := form.Locale[errorMessages[form.ErrorCode]]; hasMsg {
form.Error = msg
} else {
form.Error = errorpage.AuthenticationErrorMessage(form.ErrorCode)
form.Error = errorpage.AuthenticationErrorMessage(form.ErrorCode, form.Locale)
}
}

Expand Down