Skip to content

Commit a3b3b42

Browse files
committed
adjust Sign in with OpenID to Sign in with and let OpenID be replaceable (e.g. Google, Office 365, Authentik, Okta, etc).
1 parent 7c6c81a commit a3b3b42

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

internal/config/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ var (
121121
RenderOpenAPI: true,
122122
Languages: []string{"en"},
123123
OIDC: httpd.OIDC{
124+
DisplayName: "OpenID",
124125
ClientID: "",
125126
ClientSecret: "",
126127
ClientSecretFile: "",
@@ -1626,6 +1627,12 @@ func getHTTPDOIDCFromEnv(idx int) (httpd.OIDC, bool) {
16261627
isSet = true
16271628
}
16281629

1630+
displayName, ok := os.LookupEnv(fmt.Sprintf("SFTPGO_HTTPD__BINDINGS__%v__OIDC__DISPLAY_NAME", idx))
1631+
if ok {
1632+
result.DisplayName = displayName
1633+
isSet = true
1634+
}
1635+
16291636
redirectBaseURL, ok := os.LookupEnv(fmt.Sprintf("SFTPGO_HTTPD__BINDINGS__%v__OIDC__REDIRECT_BASE_URL", idx))
16301637
if ok {
16311638
result.RedirectBaseURL = redirectBaseURL

internal/httpd/oidc.go

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ type OIDC struct {
7676
// "web_root" if configured
7777
RedirectBaseURL string `json:"redirect_base_url" mapstructure:"redirect_base_url"`
7878
// ID token claims field to map to the SFTPGo username
79+
DisplayName string `json:"display_name" mapstructure:"display_name"`
80+
// sets the label to display for the OIDC provider
7981
UsernameField string `json:"username_field" mapstructure:"username_field"`
8082
// Optional ID token claims field to map to a SFTPGo role.
8183
// If the defined ID token claims field is set to "admin" the authenticated user

internal/httpd/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func (s *httpdServer) renderClientLoginPage(w http.ResponseWriter, r *http.Reque
192192
data.ForgotPwdURL = webClientForgotPwdPath
193193
}
194194
if s.binding.OIDC.isEnabled() && !s.binding.isWebClientOIDCLoginDisabled() {
195+
data.OpenIDDisplayName = s.binding.OIDC.DisplayName
195196
data.OpenIDLoginURL = webClientOIDCLoginPath
196197
}
197198
renderClientTemplate(w, templateCommonLogin, data)
@@ -608,6 +609,7 @@ func (s *httpdServer) renderAdminLoginPage(w http.ResponseWriter, r *http.Reques
608609
data.ForgotPwdURL = webAdminForgotPwdPath
609610
}
610611
if s.binding.OIDC.hasRoles() && !s.binding.isWebAdminOIDCLoginDisabled() {
612+
data.OpenIDDisplayName = s.binding.OIDC.DisplayName
611613
data.OpenIDLoginURL = webAdminOIDCLoginPath
612614
}
613615
renderAdminTemplate(w, templateCommonLogin, data)

internal/httpd/web.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,19 @@ type commonBasePage struct {
5858

5959
type loginPage struct {
6060
commonBasePage
61-
CurrentURL string
62-
Error *util.I18nError
63-
CSRFToken string
64-
AltLoginURL string
65-
AltLoginName string
66-
ForgotPwdURL string
67-
OpenIDLoginURL string
68-
Title string
69-
Branding UIBranding
70-
Languages []string
71-
FormDisabled bool
72-
CheckRedirect bool
61+
CurrentURL string
62+
Error *util.I18nError
63+
CSRFToken string
64+
AltLoginURL string
65+
AltLoginName string
66+
ForgotPwdURL string
67+
OpenIDLoginURL string
68+
OpenIDDisplayName string
69+
Title string
70+
Branding UIBranding
71+
Languages []string
72+
FormDisabled bool
73+
CheckRedirect bool
7374
}
7475

7576
type twoFactorPage struct {

sftpgo.json

+1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@
290290
"en"
291291
],
292292
"oidc": {
293+
"display_name": "OpenID",
293294
"client_id": "",
294295
"client_secret": "",
295296
"client_secret_file": "",

static/locales/en/translation.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"forgot_password_msg": "Enter your account username below, you will receive a password reset code by email.",
8282
"send_reset_code": "Send Reset Code",
8383
"signin": "Sign in",
84-
"signin_openid": "Sign in with OpenID",
84+
"signin_with": "Sign in with",
8585
"signout": "Sign out",
8686
"auth_code": "Authentication code",
8787
"two_factor_help": "Open the two-factor authentication app on your device to view your authentication code and verify your identity.",

static/locales/it/translation.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"forgot_password_msg": "Inserisci il nome utente del tuo account qui sotto, riceverai un codice di reimpostazione della password via e-mail.",
8282
"send_reset_code": "Invia codice di ripristino",
8383
"signin": "Accedi",
84-
"signin_openid": "Accedi con OpenID",
84+
"signin_with": "Accedi con",
8585
"signout": "Esci",
8686
"auth_code": "Codice di autenticazione",
8787
"two_factor_help": "Apri l'app di autenticazione a due fattori sul tuo dispositivo per visualizzare il tuo codice di autenticazione e verificare la tua identità.",

templates/common/login.html

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ <h1 class="text-gray-900 mb-3 ms-3">
7272
{{- if .OpenIDLoginURL}}
7373
<a href="{{.OpenIDLoginURL}}" class="btn btn-flex btn-outline flex-center {{if .FormDisabled}}btn-primary{{else}}btn-active-color-primary bg-state-light{{end}} btn-lg w-100 my-5">
7474
<img alt="Logo" src="{{.StaticURL}}/img/openid-logo.png" class="h-20px me-3" />
75-
<span data-i18n="login.signin_openid">Sign in with OpenID</span>
75+
<span data-i18n="login.signin_with">Sign in with</span>
76+
&nbsp;
77+
{{- if .OpenIDDisplayName}}
78+
{{ .OpenIDDisplayName }}
79+
{{- else}}
80+
OpenID
81+
{{- end}}
7682
</a>
7783
{{- end}}
7884
</div>
@@ -98,4 +104,4 @@ <h1 class="text-gray-900 mb-3 ms-3">
98104
{{- end}}
99105
</div>
100106
</div>
101-
{{- end}}
107+
{{- end}}

0 commit comments

Comments
 (0)