SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat(user): add v2 reset password endpoint (#12489)
Vikrant Guptadb5f4b4cd59d
diff --git a/docs/api/openapi.yml b/docs/api/openapi.ymlindex 16fda9f592..98ee485b15 100644--- a/docs/api/openapi.yml+++ b/docs/api/openapi.yml@@ -12198,9 +12198,9 @@ paths:- dashboard/api/v1/resetPassword:post:- deprecated: false+ deprecated: truedescription: This endpoint resets the password by token- operationId: ResetPassword+ operationId: ResetPasswordDeprecatedrequestBody:content:application/json:@@ -15567,6 +15567,41 @@ paths:summary: Forgot passwordtags:- users+ /api/v2/factor_password/reset:+ post:+ deprecated: false+ description: This endpoint resets the password using a single use reset password+ token+ operationId: ResetPassword+ requestBody:+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/TypesPostableResetPassword'+ responses:+ "204":+ description: No Content+ "400":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Bad Request+ "404":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Not Found+ "500":+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/RenderErrorResponse'+ description: Internal Server Error+ summary: Reset password+ tags:+ - users/api/v2/features:get:deprecated: falsediff --git a/frontend/src/api/generated/services/users/index.ts b/frontend/src/api/generated/services/users/index.tsindex cc5b692dbe..8e53342f90 100644--- a/frontend/src/api/generated/services/users/index.ts+++ b/frontend/src/api/generated/services/users/index.ts@@ -255,9 +255,10 @@ export const useCreateInvite = <};/*** This endpoint resets the password by token+ * @deprecated* @summary Reset password*/-export const resetPassword = (+export const resetPasswordDeprecated = (typesPostableResetPasswordDTO?: BodyType<TypesPostableResetPasswordDTO>,signal?: AbortSignal,) => {@@ -270,23 +271,23 @@ export const resetPassword = (});};-export const getResetPasswordMutationOptions = <+export const getResetPasswordDeprecatedMutationOptions = <TError = ErrorType<RenderErrorResponseDTO>,TContext = unknown,>(options?: {mutation?: UseMutationOptions<- Awaited<ReturnType<typeof resetPassword>>,+ Awaited<ReturnType<typeof resetPasswordDeprecated>>,TError,{ data?: BodyType<TypesPostableResetPasswordDTO> },TContext>;}): UseMutationOptions<- Awaited<ReturnType<typeof resetPassword>>,+ Awaited<ReturnType<typeof resetPasswordDeprecated>>,TError,{ data?: BodyType<TypesPostableResetPasswordDTO> },TContext> => {- const mutationKey = ['resetPassword'];+ const mutationKey = ['resetPasswordDeprecated'];const { mutation: mutationOptions } = options? options.mutation &&'mutationKey' in options.mutation &&@@ -296,45 +297,47 @@ export const getResetPasswordMutationOptions = <: { mutation: { mutationKey } };const mutationFn: MutationFunction<- Awaited<ReturnType<typeof resetPassword>>,+ Awaited<ReturnType<typeof resetPasswordDeprecated>>,{ data?: BodyType<TypesPostableResetPasswordDTO> }> = (props) => {const { data } = props ?? {};- return resetPassword(data);+ return resetPasswordDeprecated(data);};return { mutationFn, ...mutationOptions };};-export type ResetPasswordMutationResult = NonNullable<- Awaited<ReturnType<typeof resetPassword>>+export type ResetPasswordDeprecatedMutationResult = NonNullable<+ Awaited<ReturnType<typeof resetPasswordDeprecated>>>;-export type ResetPasswordMutationBody =+export type ResetPasswordDeprecatedMutationBody =| BodyType<TypesPostableResetPasswordDTO>| undefined;-export type ResetPasswordMutationError = ErrorType<RenderErrorResponseDTO>;+export type ResetPasswordDeprecatedMutationError =+ ErrorType<RenderErrorResponseDTO>;/**+ * @deprecated* @summary Reset password*/-export const useResetPassword = <+export const useResetPasswordDeprecated = <TError = ErrorType<RenderErrorResponseDTO>,TContext = unknown,>(options?: {mutation?: UseMutationOptions<- Awaited<ReturnType<typeof resetPassword>>,+ Awaited<ReturnType<typeof resetPasswordDeprecated>>,TError,{ data?: BodyType<TypesPostableResetPasswordDTO> },TContext>;}): UseMutationResult<- Awaited<ReturnType<typeof resetPassword>>,+ Awaited<ReturnType<typeof resetPasswordDeprecated>>,TError,{ data?: BodyType<TypesPostableResetPasswordDTO> },TContext> => {- return useMutation(getResetPasswordMutationOptions(options));+ return useMutation(getResetPasswordDeprecatedMutationOptions(options));};/*** This endpoint lists all users@@ -593,6 +596,89 @@ export const useForgotPassword = <> => {return useMutation(getForgotPasswordMutationOptions(options));};+/**+ * This endpoint resets the password using a single use reset password token+ * @summary Reset password+ */+export const resetPassword = (+ typesPostableResetPasswordDTO?: BodyType<TypesPostableResetPasswordDTO>,+ signal?: AbortSignal,+) => {+ return GeneratedAPIInstance<void>({+ url: `/api/v2/factor_password/reset`,+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ data: typesPostableResetPasswordDTO,+ signal,+ });+};++export const getResetPasswordMutationOptions = <+ TError = ErrorType<RenderErrorResponseDTO>,+ TContext = unknown,+>(options?: {+ mutation?: UseMutationOptions<+ Awaited<ReturnType<typeof resetPassword>>,+ TError,+ { data?: BodyType<TypesPostableResetPasswordDTO> },+ TContext+ >;+}): UseMutationOptions<+ Awaited<ReturnType<typeof resetPassword>>,+ TError,+ { data?: BodyType<TypesPostableResetPasswordDTO> },+ TContext+> => {+ const mutationKey = ['resetPassword'];+ const { mutation: mutationOptions } = options+ ? options.mutation &&+ 'mutationKey' in options.mutation &&+ options.mutation.mutationKey+ ? options+ : { ...options, mutation: { ...options.mutation, mutationKey } }+ : { mutation: { mutationKey } };++ const mutationFn: MutationFunction<+ Awaited<ReturnType<typeof resetPassword>>,+ { data?: BodyType<TypesPostableResetPasswordDTO> }+ > = (props) => {+ const { data } = props ?? {};++ return resetPassword(data);+ };++ return { mutationFn, ...mutationOptions };+};++export type ResetPasswordMutationResult = NonNullable<+ Awaited<ReturnType<typeof resetPassword>>+>;+export type ResetPasswordMutationBody =+ | BodyType<TypesPostableResetPasswordDTO>+ | undefined;+export type ResetPasswordMutationError = ErrorType<RenderErrorResponseDTO>;++/**+ * @summary Reset password+ */+export const useResetPassword = <+ TError = ErrorType<RenderErrorResponseDTO>,+ TContext = unknown,+>(options?: {+ mutation?: UseMutationOptions<+ Awaited<ReturnType<typeof resetPassword>>,+ TError,+ { data?: BodyType<TypesPostableResetPasswordDTO> },+ TContext+ >;+}): UseMutationResult<+ Awaited<ReturnType<typeof resetPassword>>,+ TError,+ { data?: BodyType<TypesPostableResetPasswordDTO> },+ TContext+> => {+ return useMutation(getResetPasswordMutationOptions(options));+};/*** This endpoint verifies whether a reset password token exists and is not expired* @summary Verify a reset password tokendiff --git a/pkg/apiserver/signozapiserver/user.go b/pkg/apiserver/signozapiserver/user.goindex 8b16024ca9..d03473c3d0 100644--- a/pkg/apiserver/signozapiserver/user.go+++ b/pkg/apiserver/signozapiserver/user.go@@ -249,7 +249,7 @@ func (provider *provider) addUserRoutes(router *mux.Router) error {}if err := router.Handle("/api/v1/resetPassword", handler.New(provider.authzMiddleware.OpenAccess(provider.userHandler.ResetPassword), handler.OpenAPIDef{- ID: "ResetPassword",+ ID: "ResetPasswordDeprecated",Tags: []string{"users"},Summary: "Reset password",Description: "This endpoint resets the password by token",@@ -259,7 +259,7 @@ func (provider *provider) addUserRoutes(router *mux.Router) error {ResponseContentType: "",SuccessStatusCode: http.StatusNoContent,ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusConflict},- Deprecated: false,+ Deprecated: true,SecuritySchemes: []handler.OpenAPISecurityScheme{},})).Methods(http.MethodPost).GetError(); err != nil {return err@@ -299,6 +299,23 @@ func (provider *provider) addUserRoutes(router *mux.Router) error {return err}+ if err := router.Handle("/api/v2/factor_password/reset", handler.New(provider.authzMiddleware.OpenAccess(provider.userHandler.ResetPassword), handler.OpenAPIDef{+ ID: "ResetPassword",+ Tags: []string{"users"},+ Summary: "Reset password",+ Description: "This endpoint resets the password using a single use reset password token",+ Request: new(types.PostableResetPassword),+ RequestContentType: "application/json",+ Response: nil,+ ResponseContentType: "",+ SuccessStatusCode: http.StatusNoContent,+ ErrorStatusCodes: []int{http.StatusBadRequest, http.StatusNotFound},+ Deprecated: false,+ SecuritySchemes: []handler.OpenAPISecurityScheme{},+ })).Methods(http.MethodPost).GetError(); err != nil {+ return err+ }+if err := router.Handle("/api/v2/users/{id}/roles", handler.New(provider.authzMiddleware.AdminAccess(provider.userHandler.GetRolesByUserID), handler.OpenAPIDef{ID: "GetRolesByUserID",Tags: []string{"users"},diff --git a/pkg/modules/user/impluser/handler.go b/pkg/modules/user/impluser/handler.goindex ec6d061a18..ce12347328 100644--- a/pkg/modules/user/impluser/handler.go+++ b/pkg/modules/user/impluser/handler.go@@ -391,7 +391,7 @@ func (handler *handler) ResetPassword(w http.ResponseWriter, r *http.Request) {defer cancel()req := new(types.PostableResetPassword)- if err := json.NewDecoder(r.Body).Decode(req); err != nil {+ if err := binding.JSON.BindBody(r.Body, req); err != nil {render.Error(w, err)return}diff --git a/tests/integration/tests/passwordauthn/03_password.py b/tests/integration/tests/passwordauthn/03_password.pyindex 935ec9a9c3..006bd67ab5 100644--- a/tests/integration/tests/passwordauthn/03_password.py+++ b/tests/integration/tests/passwordauthn/03_password.py@@ -130,6 +130,45 @@ def test_reset_password(signoz: types.SigNoz, get_token: Callable[[str, str], stassert token is not None+def test_reset_password_v2(signoz: types.SigNoz, get_token: Callable[[str, str], str]) -> None:+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)++ found_user = find_user_by_email(signoz, admin_token, PASSWORD_USER_EMAIL)++ response = requests.put(+ signoz.self.host_configs["8080"].get(f"/api/v2/users/{found_user['id']}/reset_password_tokens"),+ headers={"Authorization": f"Bearer {admin_token}"},+ timeout=2,+ )+ assert response.status_code == HTTPStatus.CREATED, response.text+ token = response.json()["data"]["token"]++ # A password failing the strength policy is rejected without consuming the token+ response = requests.post(+ signoz.self.host_configs["8080"].get("/api/v2/factor_password/reset"),+ json={"password": "password", "token": token},+ timeout=2,+ )+ assert response.status_code == HTTPStatus.BAD_REQUEST, response.text++ response = requests.post(+ signoz.self.host_configs["8080"].get("/api/v2/factor_password/reset"),+ json={"password": "resetV2Password123Z$", "token": token},+ timeout=2,+ )+ assert response.status_code == HTTPStatus.NO_CONTENT, response.text++ assert get_token(PASSWORD_USER_EMAIL, "resetV2Password123Z$") is not None++ # The token is single use, so replaying it no longer resolves+ response = requests.post(+ signoz.self.host_configs["8080"].get("/api/v2/factor_password/reset"),+ json={"password": "resetV2Password456Z$", "token": token},+ timeout=2,+ )+ assert response.status_code == HTTPStatus.NOT_FOUND, response.text++def test_reset_password_with_no_password(signoz: types.SigNoz, get_token: Callable[[str, str], str]) -> None:admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)