Skip to content

Commit 69fce04

Browse files
normana10kylecarbs
andauthored
feat: Allow hiding password auth, changing OpenID Connect text and OpenID Connect icon (#5101)
* Allow hiding password entry, changing OpenID Connect text and OpenID Connect icon * Docs * Cleaning * Fix Prettier and Go test and TS compile error * Fix LoginPage test * Prettier * Fix storybook * Add query param to un-hide password auth * Cleaning * Hide password by default when OIDC enabled * Ran prettier, updated goldenfiles and ran "make gen" * Fixed and added LoginPage test * Ran prettier * PR Feedback and split up SignInForm.tsx * Updated golden files * Fix auto-genned-files * make gen -B * Revert provisioner files? * Fix lint error --------- Co-authored-by: Kyle Carberry <kyle@coder.com>
1 parent 480f3b6 commit 69fce04

23 files changed

+571
-200
lines changed

cli/deployment/config.go

+11
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ func newConfig() *codersdk.DeploymentConfig {
254254
Flag: "oidc-username-field",
255255
Default: "preferred_username",
256256
},
257+
SignInText: &codersdk.DeploymentConfigField[string]{
258+
Name: "OpenID Connect sign in text",
259+
Usage: "The text to show on the OpenID Connect sign in button",
260+
Flag: "oidc-sign-in-text",
261+
Default: "OpenID Connect",
262+
},
263+
IconURL: &codersdk.DeploymentConfigField[string]{
264+
Name: "OpenID connect icon URL",
265+
Usage: "URL pointing to the icon to use on the OepnID Connect login button",
266+
Flag: "oidc-icon-url",
267+
},
257268
},
258269

259270
Telemetry: &codersdk.TelemetryConfig{

cli/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
552552
EmailDomain: cfg.OIDC.EmailDomain.Value,
553553
AllowSignups: cfg.OIDC.AllowSignups.Value,
554554
UsernameField: cfg.OIDC.UsernameField.Value,
555+
SignInText: cfg.OIDC.SignInText.Value,
556+
IconURL: cfg.OIDC.IconURL.Value,
555557
}
556558
}
557559

cli/testdata/coder_server_--help.golden

+7
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ Flags:
148148
--oidc-email-domain strings Email domains that clients logging in
149149
with OIDC must match.
150150
Consumes $CODER_OIDC_EMAIL_DOMAIN
151+
--oidc-icon-url string URL pointing to the icon to use on the
152+
OepnID Connect login button
153+
Consumes $CODER_OIDC_ICON_URL
151154
--oidc-ignore-email-verified Ignore the email_verified claim from the
152155
upstream provider.
153156
Consumes $CODER_OIDC_IGNORE_EMAIL_VERIFIED
@@ -157,6 +160,10 @@ Flags:
157160
OIDC.
158161
Consumes $CODER_OIDC_SCOPES (default
159162
[openid,profile,email])
163+
--oidc-sign-in-text string The text to show on the OpenID Connect
164+
sign in button
165+
Consumes $CODER_OIDC_SIGN_IN_TEXT
166+
(default "OpenID Connect")
160167
--oidc-username-field string OIDC claim field to use as the username.
161168
Consumes $CODER_OIDC_USERNAME_FIELD
162169
(default "preferred_username")

coderd/apidoc/docs.go

+31-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+31-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/userauth.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,24 @@ type GithubOAuth2Config struct {
5151
// @Success 200 {object} codersdk.AuthMethods
5252
// @Router /users/authmethods [get]
5353
func (api *API) userAuthMethods(rw http.ResponseWriter, r *http.Request) {
54+
var signInText string
55+
var iconURL string
56+
57+
if api.OIDCConfig != nil {
58+
signInText = api.OIDCConfig.SignInText
59+
}
60+
if api.OIDCConfig != nil {
61+
iconURL = api.OIDCConfig.IconURL
62+
}
63+
5464
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.AuthMethods{
55-
Password: true,
56-
Github: api.GithubOAuth2Config != nil,
57-
OIDC: api.OIDCConfig != nil,
65+
Password: codersdk.AuthMethod{Enabled: true},
66+
Github: codersdk.AuthMethod{Enabled: api.GithubOAuth2Config != nil},
67+
OIDC: codersdk.OIDCAuthMethod{
68+
AuthMethod: codersdk.AuthMethod{Enabled: api.OIDCConfig != nil},
69+
SignInText: signInText,
70+
IconURL: iconURL,
71+
},
5872
})
5973
}
6074

@@ -215,6 +229,10 @@ type OIDCConfig struct {
215229
// UsernameField selects the claim field to be used as the created user's
216230
// username.
217231
UsernameField string
232+
// SignInText is the text to display on the OIDC login button
233+
SignInText string
234+
// IconURL points to the URL of an icon to display on the OIDC login button
235+
IconURL string
218236
}
219237

220238
// @Summary OpenID Connect Callback

coderd/userauth_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func TestUserAuthMethods(t *testing.T) {
7777

7878
methods, err := client.AuthMethods(ctx)
7979
require.NoError(t, err)
80-
require.True(t, methods.Password)
81-
require.False(t, methods.Github)
80+
require.True(t, methods.Password.Enabled)
81+
require.False(t, methods.Github.Enabled)
8282
})
8383
t.Run("Github", func(t *testing.T) {
8484
t.Parallel()
@@ -91,8 +91,8 @@ func TestUserAuthMethods(t *testing.T) {
9191

9292
methods, err := client.AuthMethods(ctx)
9393
require.NoError(t, err)
94-
require.True(t, methods.Password)
95-
require.True(t, methods.Github)
94+
require.True(t, methods.Password.Enabled)
95+
require.True(t, methods.Github.Enabled)
9696
})
9797
}
9898

codersdk/deployment.go

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ type OIDCConfig struct {
200200
Scopes *DeploymentConfigField[[]string] `json:"scopes" typescript:",notnull"`
201201
IgnoreEmailVerified *DeploymentConfigField[bool] `json:"ignore_email_verified" typescript:",notnull"`
202202
UsernameField *DeploymentConfigField[string] `json:"username_field" typescript:",notnull"`
203+
SignInText *DeploymentConfigField[string] `json:"sign_in_text" typescript:",notnull"`
204+
IconURL *DeploymentConfigField[string] `json:"icon_url" typescript:",notnull"`
203205
}
204206

205207
type TelemetryConfig struct {

codersdk/users.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,21 @@ type CreateOrganizationRequest struct {
105105
Name string `json:"name" validate:"required,username"`
106106
}
107107

108-
// AuthMethods contains whether authentication types are enabled or not.
108+
// AuthMethods contains authentication method information like whether they are enabled or not or custom text, etc.
109109
type AuthMethods struct {
110-
Password bool `json:"password"`
111-
Github bool `json:"github"`
112-
OIDC bool `json:"oidc"`
110+
Password AuthMethod `json:"password"`
111+
Github AuthMethod `json:"github"`
112+
OIDC OIDCAuthMethod `json:"oidc"`
113+
}
114+
115+
type AuthMethod struct {
116+
Enabled bool `json:"enabled"`
117+
}
118+
119+
type OIDCAuthMethod struct {
120+
AuthMethod
121+
SignInText string `json:"signInText"`
122+
IconURL string `json:"iconUrl"`
113123
}
114124

115125
// HasFirstUser returns whether the first user has been created.

docs/admin/auth.md

+7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ CODER_OIDC_IGNORE_EMAIL_VERIFIED=true
131131
132132
When a new user is created, the `preferred_username` claim becomes the username. If this claim is empty, the email address will be stripped of the domain, and become the username (e.g. `example@coder.com` becomes `example`).
133133

134+
If you'd like to change the OpenID Connect button text and/or icon, you can configure them like so:
135+
136+
```console
137+
CODER_OIDC_SIGN_IN_TEXT="Sign in with Gitea"
138+
CODER_OIDC_ICON_URL=https://gitea.io/images/gitea.png
139+
```
140+
134141
## SCIM (enterprise)
135142

136143
Coder supports user provisioning and deprovisioning via SCIM 2.0 with header

docs/api/general.md

+22
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,17 @@ curl -X GET http://coder-server:8080/api/v2/config/deployment \
562562
"usage": "string",
563563
"value": ["string"]
564564
},
565+
"icon_url": {
566+
"default": "string",
567+
"enterprise": true,
568+
"flag": "string",
569+
"hidden": true,
570+
"name": "string",
571+
"secret": true,
572+
"shorthand": "string",
573+
"usage": "string",
574+
"value": "string"
575+
},
565576
"ignore_email_verified": {
566577
"default": true,
567578
"enterprise": true,
@@ -595,6 +606,17 @@ curl -X GET http://coder-server:8080/api/v2/config/deployment \
595606
"usage": "string",
596607
"value": ["string"]
597608
},
609+
"sign_in_text": {
610+
"default": "string",
611+
"enterprise": true,
612+
"flag": "string",
613+
"hidden": true,
614+
"name": "string",
615+
"secret": true,
616+
"shorthand": "string",
617+
"usage": "string",
618+
"value": "string"
619+
},
598620
"username_field": {
599621
"default": "string",
600622
"enterprise": true,

0 commit comments

Comments
 (0)