50 lines
980 B
Go
50 lines
980 B
Go
package query
|
|
|
|
import (
|
|
"context"
|
|
|
|
"forge.cadoles.com/wpetit/hydra-passwordless/internal/config"
|
|
"forge.cadoles.com/wpetit/hydra-passwordless/internal/token"
|
|
"github.com/pkg/errors"
|
|
"gitlab.com/wpetit/goweb/cqrs"
|
|
"gitlab.com/wpetit/goweb/middleware/container"
|
|
)
|
|
|
|
type VerifyUserRequest struct {
|
|
Token string
|
|
}
|
|
|
|
type VerifyUserData struct {
|
|
Email string
|
|
Challenge string
|
|
RememberMe bool
|
|
}
|
|
|
|
func HandleVerifyUserRequest(ctx context.Context, qry cqrs.Query) (interface{}, error) {
|
|
req, ok := qry.Request().(*VerifyUserRequest)
|
|
if !ok {
|
|
return nil, cqrs.ErrUnexpectedRequest
|
|
}
|
|
|
|
ctn := container.Must(ctx)
|
|
conf := config.Must(ctn)
|
|
|
|
email, challenge, rememberMe, err := token.Verify(
|
|
conf.HTTP.TokenSigningKey,
|
|
conf.HTTP.TokenEncryptionKey,
|
|
req.Token,
|
|
)
|
|
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not verify token")
|
|
}
|
|
|
|
data := &VerifyUserData{
|
|
Email: email,
|
|
Challenge: challenge,
|
|
RememberMe: rememberMe,
|
|
}
|
|
|
|
return data, nil
|
|
}
|