From 915287dc104edb63fbcf032c0c792426f06c27e8 Mon Sep 17 00:00:00 2001 From: crapStone Date: Mon, 19 Feb 2024 01:20:03 +0000 Subject: [PATCH] Add ability to specify custom names in the OAuth login buttons (#214) --- config.yml | 4 ++++ docs/configuration/cheat-sheet.md | 2 ++ internal/config/config.go | 5 +++++ internal/i18n/locales/cs-CZ.yml | 3 +-- internal/i18n/locales/en-US.yml | 4 +--- internal/i18n/locales/es-ES.yml | 3 +-- internal/i18n/locales/fr-FR.yml | 3 +-- internal/i18n/locales/hu-HU.yml | 4 +--- internal/i18n/locales/pt-BR.yml | 3 +-- internal/i18n/locales/ru-RU.yml | 3 +-- internal/i18n/locales/zh-CN.yml | 3 +-- internal/i18n/locales/zh-TW.yml | 4 +--- templates/pages/admin_config.html | 2 ++ templates/pages/auth_form.html | 6 +++--- 14 files changed, 25 insertions(+), 24 deletions(-) diff --git a/config.yml b/config.yml index 77b063d..94edcd0 100644 --- a/config.yml +++ b/config.yml @@ -78,12 +78,16 @@ gitlab.client-key: gitlab.secret: # URL of the Gitlab instance. Default: https://gitlab.com/ gitlab.url: https://gitlab.com/ +# The name of the GitLab instance. It is displayed in the OAuth login button. Default: GitLab +gitlab.name: GitLab # To create a new OAuth2 application using Gitea : https://gitea.domain/user/settings/applications gitea.client-key: gitea.secret: # URL of the Gitea instance. Default: https://gitea.com/ gitea.url: https://gitea.com/ +# The name of the Gitea instance. It is displayed in the OAuth login button. Default: Gitea +gitea.name: Gitea # To create a new OAuth2 application using OpenID Connect: oidc.client-key: diff --git a/docs/configuration/cheat-sheet.md b/docs/configuration/cheat-sheet.md index e637b1a..981af6d 100644 --- a/docs/configuration/cheat-sheet.md +++ b/docs/configuration/cheat-sheet.md @@ -24,9 +24,11 @@ | gitlab.client-key | OG_GITLAB_CLIENT_KEY | none | The client key for the GitLab OAuth application. | | gitlab.secret | OG_GITLAB_SECRET | none | The secret for the GitLab OAuth application. | | gitlab.url | OG_GITLAB_URL | `https://gitlab.com/` | The URL of the GitLab instance. | +| gitlab.name | OG_GITLAB_NAME | `GitLab` | The name of the GitLab instance. It is displayed in the OAuth login button. | | gitea.client-key | OG_GITEA_CLIENT_KEY | none | The client key for the Gitea OAuth application. | | gitea.secret | OG_GITEA_SECRET | none | The secret for the Gitea OAuth application. | | gitea.url | OG_GITEA_URL | `https://gitea.com/` | The URL of the Gitea instance. | +| gitea.name | OG_GITEA_NAME | `Gitea` | The name of the Gitea instance. It is displayed in the OAuth login button. | | oidc.client-key | OG_OIDC_CLIENT_KEY | none | The client key for the OpenID application. | | oidc.secret | OG_OIDC_SECRET | none | The secret for the OpenID application. | | oidc.discovery-url | OG_OIDC_DISCOVERY_URL | none | Discovery endpoint of the OpenID provider. | diff --git a/internal/config/config.go b/internal/config/config.go index b755c3d..b49d5a4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -52,10 +52,12 @@ type config struct { GitlabClientKey string `yaml:"gitlab.client-key" env:"OG_GITLAB_CLIENT_KEY"` GitlabSecret string `yaml:"gitlab.secret" env:"OG_GITLAB_SECRET"` GitlabUrl string `yaml:"gitlab.url" env:"OG_GITLAB_URL"` + GitlabName string `yaml:"gitlab.name" env:"OG_GITLAB_NAME"` GiteaClientKey string `yaml:"gitea.client-key" env:"OG_GITEA_CLIENT_KEY"` GiteaSecret string `yaml:"gitea.secret" env:"OG_GITEA_SECRET"` GiteaUrl string `yaml:"gitea.url" env:"OG_GITEA_URL"` + GiteaName string `yaml:"gitea.name" env:"OG_GITEA_NAME"` OIDCClientKey string `yaml:"oidc.client-key" env:"OG_OIDC_CLIENT_KEY"` OIDCSecret string `yaml:"oidc.secret" env:"OG_OIDC_SECRET"` @@ -86,7 +88,10 @@ func configWithDefaults() (*config, error) { c.SshPort = "2222" c.SshKeygen = "ssh-keygen" + c.GitlabName = "GitLab" + c.GiteaUrl = "https://gitea.com" + c.GiteaName = "Gitea" return c, nil } diff --git a/internal/i18n/locales/cs-CZ.yml b/internal/i18n/locales/cs-CZ.yml index a2fcffa..cbd953d 100644 --- a/internal/i18n/locales/cs-CZ.yml +++ b/internal/i18n/locales/cs-CZ.yml @@ -122,8 +122,7 @@ auth.username: Uživatelské jméno auth.password: Heslo auth.register-instead: Raději se zaregistrovat auth.login-instead: Raději se přihlásit -auth.github-oauth: Pokračovat s účtem na GitHubu -auth.gitea-oauth: Pokračovat s účtem na Gitea +auth.oauth: Pokračovat s účtem na %s error: Chyba diff --git a/internal/i18n/locales/en-US.yml b/internal/i18n/locales/en-US.yml index 092dec1..0b03b09 100644 --- a/internal/i18n/locales/en-US.yml +++ b/internal/i18n/locales/en-US.yml @@ -132,9 +132,7 @@ auth.username: Username auth.password: Password auth.register-instead: Register instead auth.login-instead: Login instead -auth.github-oauth: Continue with GitHub account -auth.gitlab-oauth: Continue with GitLab account -auth.gitea-oauth: Continue with Gitea account +auth.oauth: Continue with %s account error: Error diff --git a/internal/i18n/locales/es-ES.yml b/internal/i18n/locales/es-ES.yml index 89563e5..3b04529 100644 --- a/internal/i18n/locales/es-ES.yml +++ b/internal/i18n/locales/es-ES.yml @@ -115,8 +115,7 @@ auth.username: Nombre de usuario auth.password: Contraseña auth.register-instead: Registrarse en su lugar auth.login-instead: Iniciar sesión en su lugar -auth.github-oauth: Continuar con cuenta de GitHub -auth.gitea-oauth: Continuar con cuenta de Gitea +auth.oauth: Continuar con cuenta de %s error: Error diff --git a/internal/i18n/locales/fr-FR.yml b/internal/i18n/locales/fr-FR.yml index 7fcaae2..f71ec0b 100644 --- a/internal/i18n/locales/fr-FR.yml +++ b/internal/i18n/locales/fr-FR.yml @@ -115,8 +115,7 @@ auth.username: Nom d'utilisateur auth.password: Mot de passe auth.register-instead: Je préfère m'inscrire auth.login-instead: Je préfère me connecter -auth.github-oauth: Continuer avec un compte GitHub -auth.gitea-oauth: Continuer avec un compte Gitea +auth.oauth: Continuer avec un compte %s error: Erreur diff --git a/internal/i18n/locales/hu-HU.yml b/internal/i18n/locales/hu-HU.yml index 54d32bc..09d941b 100644 --- a/internal/i18n/locales/hu-HU.yml +++ b/internal/i18n/locales/hu-HU.yml @@ -132,9 +132,7 @@ auth.username: Felhasználónév auth.password: Jelszó auth.register-instead: Vagy regisztrálj auth.login-instead: Vagy jelentkezz be -auth.github-oauth: Folytatás GitHub fiókkal -auth.gitlab-oauth: Folytatás GitLab fiókkal -auth.gitea-oauth: Folytatás Gitea fiókkal +auth.oauth: Folytatás %s fiókkal error: Hiba diff --git a/internal/i18n/locales/pt-BR.yml b/internal/i18n/locales/pt-BR.yml index 4ae4dfe..8ce96ff 100644 --- a/internal/i18n/locales/pt-BR.yml +++ b/internal/i18n/locales/pt-BR.yml @@ -115,8 +115,7 @@ auth.username: Nome de usuário auth.password: Senha auth.register-instead: Registrar-se no lugar auth.login-instead: Entrar no lugar -auth.github-oauth: Continuar com conta do GitHub -auth.gitea-oauth: Continuar com conta do Gitea +auth.oauth: Continuar com conta do %s error: Erro diff --git a/internal/i18n/locales/ru-RU.yml b/internal/i18n/locales/ru-RU.yml index 4a8cd36..a25240d 100644 --- a/internal/i18n/locales/ru-RU.yml +++ b/internal/i18n/locales/ru-RU.yml @@ -115,8 +115,7 @@ auth.username: Имя пользователя auth.password: Пароль auth.register-instead: Зарегистрироваться auth.login-instead: Войти -auth.github-oauth: Войти с помощью доступа GitHub -auth.gitea-oauth: Войти с помощью доступа Gitea +auth.oauth: Войти с помощью доступа %s error: Ошибка diff --git a/internal/i18n/locales/zh-CN.yml b/internal/i18n/locales/zh-CN.yml index 079a1fd..4a0c5b6 100644 --- a/internal/i18n/locales/zh-CN.yml +++ b/internal/i18n/locales/zh-CN.yml @@ -115,8 +115,7 @@ auth.username: 用户名 auth.password: 密码 auth.register-instead: 转到注册 auth.login-instead: 转到登录 -auth.github-oauth: 使用 GitHub 账号继续 -auth.gitea-oauth: 使用 Gitea 账号继续 +auth.oauth: 使用 %s 账号继续 error: 错误 diff --git a/internal/i18n/locales/zh-TW.yml b/internal/i18n/locales/zh-TW.yml index 86532d7..d22e174 100644 --- a/internal/i18n/locales/zh-TW.yml +++ b/internal/i18n/locales/zh-TW.yml @@ -124,9 +124,7 @@ auth.username: 使用者名稱 auth.password: 密碼 auth.register-instead: 註冊 auth.login-instead: 登錄 -auth.github-oauth: 用 GitHub 帳號繼續 -auth.gitlab-oauth: 用 GitLab 帳號繼續 -auth.gitea-oauth: 用 Gitea 帳號繼續 +auth.oauth: 用 %s 帳號繼續 error: 錯誤 diff --git a/templates/pages/admin_config.html b/templates/pages/admin_config.html index b387c99..248774b 100644 --- a/templates/pages/admin_config.html +++ b/templates/pages/admin_config.html @@ -59,9 +59,11 @@
GitLab client Key
{{ .c.GitlabClientKey }}
GitLab Secret
{{ .c.GitlabSecret }}
GitLab URL
{{ .c.GitlabUrl }}
+
GitLab Name
{{ .c.GitlabName }}
Gitea client Key
{{ .c.GiteaClientKey }}
Gitea Secret
{{ .c.GiteaSecret }}
Gitea URL
{{ .c.GiteaUrl }}
+
Gitea Name
{{ .c.GiteaName }}
OIDC client Key
{{ .c.OIDCClientKey }}
OIDC Secret
{{ .c.OIDCSecret }}
OIDC Discovery URL
{{ .c.OIDCDiscoveryUrl }}
diff --git a/templates/pages/auth_form.html b/templates/pages/auth_form.html index 8bc1350..d4b403f 100644 --- a/templates/pages/auth_form.html +++ b/templates/pages/auth_form.html @@ -63,17 +63,17 @@
{{ if .githubOauth }} - {{ .locale.Tr "auth.github-oauth" }} + {{ .locale.Tr "auth.oauth" "GitHub"}} {{ end }} {{ if .gitlabOauth }} - {{ .locale.Tr "auth.gitlab-oauth" }} + {{ .locale.Tr "auth.oauth" .c.GitLabName}} {{ end }} {{ if .giteaOauth }} - {{ .locale.Tr "auth.gitea-oauth" }} + {{ .locale.Tr "auth.oauth" .c.GiteaName }} {{ end }} {{ if .oidcOauth }}