Skip to content

Commit

Permalink
Remove password field length validation for ldap logins
Browse files Browse the repository at this point in the history
Fixes #642
  • Loading branch information
StevenWeathers committed Oct 30, 2024
1 parent a68906b commit 23cc565
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
19 changes: 17 additions & 2 deletions docs/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1745,11 +1745,11 @@ const docTemplate = `{
"summary": "Login LDAP",
"parameters": [
{
"description": "user login object",
"description": "user ldap login object",
"name": "credentials",
"in": "body",
"schema": {
"$ref": "#/definitions/http.userLoginRequestBody"
"$ref": "#/definitions/http.userLoginLdapRequestBody"
}
}
],
Expand Down Expand Up @@ -11426,6 +11426,21 @@ const docTemplate = `{
}
}
},
"http.userLoginLdapRequestBody": {
"type": "object",
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"http.userLoginRequestBody": {
"type": "object",
"required": [
Expand Down
19 changes: 17 additions & 2 deletions docs/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1737,11 +1737,11 @@
"summary": "Login LDAP",
"parameters": [
{
"description": "user login object",
"description": "user ldap login object",
"name": "credentials",
"in": "body",
"schema": {
"$ref": "#/definitions/http.userLoginRequestBody"
"$ref": "#/definitions/http.userLoginLdapRequestBody"
}
}
],
Expand Down Expand Up @@ -11418,6 +11418,21 @@
}
}
},
"http.userLoginLdapRequestBody": {
"type": "object",
"required": [
"email",
"password"
],
"properties": {
"email": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"http.userLoginRequestBody": {
"type": "object",
"required": [
Expand Down
14 changes: 12 additions & 2 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,16 @@ definitions:
- password1
- password2
type: object
http.userLoginLdapRequestBody:
properties:
email:
type: string
password:
type: string
required:
- email
- password
type: object
http.userLoginRequestBody:
properties:
email:
Expand Down Expand Up @@ -3037,11 +3047,11 @@ paths:
attempts to log the user in with provided credentials
*Endpoint only available when LDAP is enabled
parameters:
- description: user login object
- description: user ldap login object
in: body
name: credentials
schema:
$ref: '#/definitions/http.userLoginRequestBody'
$ref: '#/definitions/http.userLoginLdapRequestBody'
produces:
- application/json
responses:
Expand Down
9 changes: 7 additions & 2 deletions internal/http/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func (s *Service) handleLogin() http.HandlerFunc {
}
}

type userLoginLdapRequestBody struct {
Email string `json:"email" validate:"required,email"`
Password string `json:"password" validate:"required"`
}

// handleLdapLogin attempts to authenticate the user by looking up and authenticating
// via ldap, and then creates the user if not existing and logs them in
//
Expand All @@ -106,7 +111,7 @@ func (s *Service) handleLogin() http.HandlerFunc {
// @Description *Endpoint only available when LDAP is enabled
// @Tags auth
// @Produce json
// @Param credentials body userLoginRequestBody false "user login object"
// @Param credentials body userLoginLdapRequestBody false "user ldap login object"
// @Success 200 object standardJsonResponse{data=loginResponse}
// @Failure 401 object standardJsonResponse{}
// @Failure 500 object standardJsonResponse{}
Expand All @@ -120,7 +125,7 @@ func (s *Service) handleLdapLogin() http.HandlerFunc {
return
}

var u = userLoginRequestBody{}
var u = userLoginLdapRequestBody{}
jsonErr := json.Unmarshal(body, &u)
if jsonErr != nil {
s.Failure(w, r, http.StatusBadRequest, Errorf(EINVALID, jsonErr.Error()))
Expand Down

0 comments on commit 23cc565

Please sign in to comment.