From c7ce68fea3b5b779439cb2268cc8071bdc3b5359 Mon Sep 17 00:00:00 2001 From: Joel Lee Date: Mon, 4 Mar 2024 17:10:40 +0800 Subject: [PATCH] Revert "feat: refactor resource owner password grant (#1443)" This reverts commit e63ad6ff0f67d9a83456918a972ecb5109125628. --- internal/api/token.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/internal/api/token.go b/internal/api/token.go index 52729ac4bf..2f6f9e3b22 100644 --- a/internal/api/token.go +++ b/internal/api/token.go @@ -117,29 +117,27 @@ func (a *API) ResourceOwnerPasswordGrant(ctx context.Context, w http.ResponseWri grantParams.FillGrantParams(r) - switch { - case params.Email != "" && config.External.Email.Enabled: + if params.Email != "" { provider = "email" + if !config.External.Email.Enabled { + return badRequestError("Email logins are disabled") + } user, err = models.FindUserByEmailAndAudience(db, params.Email, aud) - - case params.Phone != "" && config.External.Phone.Enabled: + } else if params.Phone != "" { provider = "phone" + if !config.External.Phone.Enabled { + return badRequestError("Phone logins are disabled") + } params.Phone = formatPhoneNumber(params.Phone) user, err = models.FindUserByPhoneAndAudience(db, params.Phone, aud) - - case !config.External.Email.Enabled: - return badRequestError("Email logins are disabled") - - case !config.External.Phone.Enabled: - return badRequestError("Phone logins are disabled") - - default: + } else { return oauthError("invalid_grant", InvalidLoginMessage) } - if err != nil && models.IsNotFoundError(err) { - return oauthError("invalid_grant", InvalidLoginMessage) - } else if err != nil { + if err != nil { + if models.IsNotFoundError(err) { + return oauthError("invalid_grant", InvalidLoginMessage) + } return internalServerError("Database error querying schema").WithInternalError(err) }