-
Notifications
You must be signed in to change notification settings - Fork 940
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: return mfa only flag * feat: add webauthn admin handler * feat: add webauthn credential handler to router * feat: add password mgmt admin endpoints * feat: add sessions admin handler * feat: add otp admin handler * feat: add otp to admin user dto * test: add admin password handler test * test: add admin webauthn handler test * test: add admin session handler test * test: add admin otp handler test * chore: merge both loadDto functions * tests: fix test name typos
- Loading branch information
1 parent
aa97808
commit c264108
Showing
28 changed files
with
1,617 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package admin | ||
|
||
import ( | ||
"github.com/gofrs/uuid" | ||
"time" | ||
) | ||
|
||
type GetOTPRequestDto struct { | ||
UserID string `param:"user_id" validate:"required,uuid4"` | ||
} | ||
|
||
type OTPDto struct { | ||
ID uuid.UUID `json:"id"` | ||
CreatedAt time.Time `json:"created_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package admin | ||
|
||
type ListWebauthnCredentialsRequestDto struct { | ||
UserID string `param:"user_id" validate:"required,uuid"` | ||
} | ||
|
||
type GetWebauthnCredentialRequestDto struct { | ||
ListWebauthnCredentialsRequestDto | ||
WebauthnCredentialID string `param:"credential_id" validate:"required"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gofrs/uuid" | ||
"github.com/labstack/echo/v4" | ||
"github.com/teamhanko/hanko/backend/dto/admin" | ||
"github.com/teamhanko/hanko/backend/persistence" | ||
"net/http" | ||
) | ||
|
||
type OTPAdminHandler interface { | ||
Get(ctx echo.Context) error | ||
Delete(ctx echo.Context) error | ||
} | ||
|
||
type otpAdminHandler struct { | ||
persister persistence.Persister | ||
} | ||
|
||
func NewOTPAdminHandler(persister persistence.Persister) OTPAdminHandler { | ||
return &otpAdminHandler{persister: persister} | ||
} | ||
|
||
func (h *otpAdminHandler) Get(ctx echo.Context) error { | ||
getDto, err := loadDto[admin.GetOTPRequestDto](ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userID, err := uuid.FromString(getDto.UserID) | ||
if err != nil { | ||
return fmt.Errorf(parseUserUuidFailureMessage, err) | ||
} | ||
|
||
userModel, err := h.persister.GetUserPersister().Get(userID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if userModel == nil || userModel.OTPSecret == nil { | ||
return echo.NewHTTPError(http.StatusNotFound) | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, admin.OTPDto{ | ||
ID: userModel.OTPSecret.ID, | ||
CreatedAt: userModel.OTPSecret.CreatedAt, | ||
}) | ||
} | ||
|
||
func (h *otpAdminHandler) Delete(ctx echo.Context) error { | ||
deleteDto, err := loadDto[admin.GetOTPRequestDto](ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
userID, err := uuid.FromString(deleteDto.UserID) | ||
if err != nil { | ||
return fmt.Errorf(parseUserUuidFailureMessage, err) | ||
} | ||
|
||
userModel, err := h.persister.GetUserPersister().Get(userID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if userModel == nil || userModel.OTPSecret == nil { | ||
return echo.NewHTTPError(http.StatusNotFound) | ||
} | ||
|
||
err = h.persister.GetOTPSecretPersister().Delete(userModel.OTPSecret) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ctx.NoContent(http.StatusNoContent) | ||
} |
Oops, something went wrong.