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>
This commit is contained in:
Arthur Normand
2023-01-31 13:33:25 -05:00
committed by GitHub
parent 480f3b6e43
commit 69fce0488e
23 changed files with 572 additions and 201 deletions

34
coderd/apidoc/docs.go generated
View File

@ -5444,17 +5444,25 @@ const docTemplate = `{
}
}
},
"codersdk.AuthMethod": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"codersdk.AuthMethods": {
"type": "object",
"properties": {
"github": {
"type": "boolean"
"$ref": "#/definitions/codersdk.AuthMethod"
},
"oidc": {
"type": "boolean"
"$ref": "#/definitions/codersdk.OIDCAuthMethod"
},
"password": {
"type": "boolean"
"$ref": "#/definitions/codersdk.AuthMethod"
}
}
},
@ -6626,6 +6634,20 @@ const docTemplate = `{
}
}
},
"codersdk.OIDCAuthMethod": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"iconUrl": {
"type": "string"
},
"signInText": {
"type": "string"
}
}
},
"codersdk.OIDCConfig": {
"type": "object",
"properties": {
@ -6641,6 +6663,9 @@ const docTemplate = `{
"email_domain": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
},
"icon_url": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
},
"ignore_email_verified": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-bool"
},
@ -6650,6 +6675,9 @@ const docTemplate = `{
"scopes": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
},
"sign_in_text": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
},
"username_field": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
}

View File

@ -4825,17 +4825,25 @@
}
}
},
"codersdk.AuthMethod": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
},
"codersdk.AuthMethods": {
"type": "object",
"properties": {
"github": {
"type": "boolean"
"$ref": "#/definitions/codersdk.AuthMethod"
},
"oidc": {
"type": "boolean"
"$ref": "#/definitions/codersdk.OIDCAuthMethod"
},
"password": {
"type": "boolean"
"$ref": "#/definitions/codersdk.AuthMethod"
}
}
},
@ -5927,6 +5935,20 @@
}
}
},
"codersdk.OIDCAuthMethod": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
},
"iconUrl": {
"type": "string"
},
"signInText": {
"type": "string"
}
}
},
"codersdk.OIDCConfig": {
"type": "object",
"properties": {
@ -5942,6 +5964,9 @@
"email_domain": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
},
"icon_url": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
},
"ignore_email_verified": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-bool"
},
@ -5951,6 +5976,9 @@
"scopes": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-array_string"
},
"sign_in_text": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
},
"username_field": {
"$ref": "#/definitions/codersdk.DeploymentConfigField-string"
}

View File

@ -51,10 +51,24 @@ type GithubOAuth2Config struct {
// @Success 200 {object} codersdk.AuthMethods
// @Router /users/authmethods [get]
func (api *API) userAuthMethods(rw http.ResponseWriter, r *http.Request) {
var signInText string
var iconURL string
if api.OIDCConfig != nil {
signInText = api.OIDCConfig.SignInText
}
if api.OIDCConfig != nil {
iconURL = api.OIDCConfig.IconURL
}
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.AuthMethods{
Password: true,
Github: api.GithubOAuth2Config != nil,
OIDC: api.OIDCConfig != nil,
Password: codersdk.AuthMethod{Enabled: true},
Github: codersdk.AuthMethod{Enabled: api.GithubOAuth2Config != nil},
OIDC: codersdk.OIDCAuthMethod{
AuthMethod: codersdk.AuthMethod{Enabled: api.OIDCConfig != nil},
SignInText: signInText,
IconURL: iconURL,
},
})
}
@ -215,6 +229,10 @@ type OIDCConfig struct {
// UsernameField selects the claim field to be used as the created user's
// username.
UsernameField string
// SignInText is the text to display on the OIDC login button
SignInText string
// IconURL points to the URL of an icon to display on the OIDC login button
IconURL string
}
// @Summary OpenID Connect Callback

View File

@ -77,8 +77,8 @@ func TestUserAuthMethods(t *testing.T) {
methods, err := client.AuthMethods(ctx)
require.NoError(t, err)
require.True(t, methods.Password)
require.False(t, methods.Github)
require.True(t, methods.Password.Enabled)
require.False(t, methods.Github.Enabled)
})
t.Run("Github", func(t *testing.T) {
t.Parallel()
@ -91,8 +91,8 @@ func TestUserAuthMethods(t *testing.T) {
methods, err := client.AuthMethods(ctx)
require.NoError(t, err)
require.True(t, methods.Password)
require.True(t, methods.Github)
require.True(t, methods.Password.Enabled)
require.True(t, methods.Github.Enabled)
})
}