diff --git a/cmd/auth.go b/cmd/auth.go index 89d7b285..3ca81568 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -2,6 +2,7 @@ package main import ( "net/http" + "net/url" "strings" "time" @@ -15,11 +16,19 @@ type loginTpl struct { Title string Description string - NextURI string - Nonce string - PasswordEnabled bool - OIDCEnabled bool - Error string + NextURI string + Nonce string + PasswordEnabled bool + OIDCProvider string + OIDCProviderLogo string + Error string +} + +var oidcProviders = map[string]bool{ + "google.com": true, + "microsoftonline.com": true, + "auth0.com": true, + "github.com": true, } // handleLoginPage renders the login page and handles the login form. @@ -33,11 +42,33 @@ func handleLoginPage(c echo.Context) error { next = uriAdmin } + oidcProvider := "" + oidcProviderLogo := "" + if app.constants.Security.OIDC.Enabled { + oidcProviderLogo = "oidc.png" + u, err := url.Parse(app.constants.Security.OIDC.Provider) + if err == nil { + h := strings.Split(u.Hostname(), ".") + + // Get the last two h for the root domain + if len(h) >= 2 { + oidcProvider = h[len(h)-2] + "." + h[len(h)-1] + } else { + oidcProvider = u.Hostname() + } + + if _, ok := oidcProviders[oidcProvider]; ok { + oidcProviderLogo = oidcProvider + ".png" + } + } + } + out := loginTpl{ - Title: app.i18n.T("users.login"), - PasswordEnabled: true, - OIDCEnabled: true, - NextURI: next, + Title: app.i18n.T("users.login"), + PasswordEnabled: true, + OIDCProvider: oidcProvider, + OIDCProviderLogo: oidcProviderLogo, + NextURI: next, } // Login request. diff --git a/i18n/en.json b/i18n/en.json index 382442b9..a993e649 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -596,7 +596,7 @@ "templates.rawHTML": "Raw HTML", "templates.subject": "Subject", "users.login": "Login", - "users.loginOIDC": "Login with OIDC", + "users.loginOIDC": "Login with {name}", "users.logout": "Logout", "users.profile": "Profile", "users.lastLogin": "Last login", diff --git a/static/public/static/auth/auth0.com.png b/static/public/static/auth/auth0.com.png new file mode 100644 index 00000000..3b2d8562 Binary files /dev/null and b/static/public/static/auth/auth0.com.png differ diff --git a/static/public/static/auth/github.com.png b/static/public/static/auth/github.com.png new file mode 100644 index 00000000..1fa19c55 Binary files /dev/null and b/static/public/static/auth/github.com.png differ diff --git a/static/public/static/auth/google.com.png b/static/public/static/auth/google.com.png new file mode 100644 index 00000000..389c1cd5 Binary files /dev/null and b/static/public/static/auth/google.com.png differ diff --git a/static/public/static/auth/microsoftonline.com.png b/static/public/static/auth/microsoftonline.com.png new file mode 100644 index 00000000..168a9c81 Binary files /dev/null and b/static/public/static/auth/microsoftonline.com.png differ diff --git a/static/public/static/auth/oidc.png b/static/public/static/auth/oidc.png new file mode 100644 index 00000000..7b53d129 Binary files /dev/null and b/static/public/static/auth/oidc.png differ diff --git a/static/public/static/style.css b/static/public/static/style.css index 8808c4b5..a47267c3 100644 --- a/static/public/static/style.css +++ b/static/public/static/style.css @@ -87,7 +87,8 @@ input[disabled] { color: #0055d4; } .button.button-outline:hover { - background-color: #0055d4; + border-color: #333; + background-color: #333; color: #fff; } @@ -181,6 +182,21 @@ input[disabled] { font-weight: bold; } +.login .submit { + margin-top: 20px; +} + .login button { + width: 100%; + vertical-align: middle; + display: flex; + align-items: center; + justify-content: center; + } + .login button img { + max-width: 24px; + margin-right: 10px; + } + #btn-back { display: none; } diff --git a/static/public/templates/login.html b/static/public/templates/login.html index 596ca2f3..b8b8524a 100644 --- a/static/public/templates/login.html +++ b/static/public/templates/login.html @@ -1,7 +1,7 @@ {{ define "admin-login" }} {{ template "header" .}} -
+

{{ .L.T "users.login"}}

{{ if .Data.PasswordEnabled }}
@@ -19,16 +19,19 @@ {{ if .Data.Error }}

{{ .Data.Error }}

{{ end }} -

+

{{ end }} - {{ if .Data.OIDCEnabled }} + {{ if .Data.OIDCProvider }}
-

+

{{ end }}