mirror of
https://github.com/openziti/zrok.git
synced 2024-11-29 03:24:15 +01:00
shortuuid for tokens (#59)
This commit is contained in:
parent
de3412e3d1
commit
366f7db982
@ -33,11 +33,7 @@ func (self *createAccountHandler) handleDirectCreate(params identity.CreateAccou
|
|||||||
return identity.NewCreateAccountBadRequest().WithPayload("missing email or password")
|
return identity.NewCreateAccountBadRequest().WithPayload("missing email or password")
|
||||||
}
|
}
|
||||||
|
|
||||||
token, err := generateApiToken()
|
token := createToken()
|
||||||
if err != nil {
|
|
||||||
logrus.Errorf("error generating api token: %v", err)
|
|
||||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
|
||||||
}
|
|
||||||
a := &store.Account{
|
a := &store.Account{
|
||||||
Email: params.Body.Email,
|
Email: params.Body.Email,
|
||||||
Password: hashPassword(params.Body.Password),
|
Password: hashPassword(params.Body.Password),
|
||||||
@ -67,11 +63,7 @@ func (self *createAccountHandler) handleVerifiedCreate(params identity.CreateAcc
|
|||||||
logrus.Errorf("missing email")
|
logrus.Errorf("missing email")
|
||||||
return identity.NewCreateAccountBadRequest().WithPayload("missing email")
|
return identity.NewCreateAccountBadRequest().WithPayload("missing email")
|
||||||
}
|
}
|
||||||
token, err := generateApiToken()
|
token := createToken()
|
||||||
if err != nil {
|
|
||||||
logrus.Errorf("error generating api token: %v", err)
|
|
||||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
|
||||||
}
|
|
||||||
if err := sendVerificationEmail(params.Body.Email, token, self.cfg); err != nil {
|
if err := sendVerificationEmail(params.Body.Email, token, self.cfg); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
return identity.NewCreateAccountInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
|
@ -93,11 +93,7 @@ func (self *enableHandler) Handle(params identity.EnableParams, principal *rest_
|
|||||||
|
|
||||||
func (_ *enableHandler) createIdentity(email string, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.CreateIdentityCreated, error) {
|
func (_ *enableHandler) createIdentity(email string, client *rest_management_api_client.ZitiEdgeManagement) (*identity_edge.CreateIdentityCreated, error) {
|
||||||
iIsAdmin := false
|
iIsAdmin := false
|
||||||
iId, err := randomId()
|
name := createToken()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
name := fmt.Sprintf("%v-%v", email, iId)
|
|
||||||
identityType := rest_model_edge.IdentityTypeUser
|
identityType := rest_model_edge.IdentityTypeUser
|
||||||
i := &rest_model_edge.IdentityCreate{
|
i := &rest_model_edge.IdentityCreate{
|
||||||
Enrollment: &rest_model_edge.IdentityCreateEnrollment{Ott: true},
|
Enrollment: &rest_model_edge.IdentityCreateEnrollment{Ott: true},
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
errors2 "github.com/go-openapi/errors"
|
errors2 "github.com/go-openapi/errors"
|
||||||
|
"github.com/lithammer/shortuuid/v4"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||||
"github.com/openziti/edge/rest_management_api_client"
|
"github.com/openziti/edge/rest_management_api_client"
|
||||||
"github.com/openziti/edge/rest_util"
|
"github.com/openziti/edge/rest_util"
|
||||||
@ -41,12 +42,8 @@ func edgeClient(cfg *ZitiConfig) (*rest_management_api_client.ZitiEdgeManagement
|
|||||||
return rest_util.NewEdgeManagementClientWithUpdb(cfg.Username, cfg.Password, cfg.ApiEndpoint, caPool)
|
return rest_util.NewEdgeManagementClientWithUpdb(cfg.Username, cfg.Password, cfg.ApiEndpoint, caPool)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateApiToken() (string, error) {
|
func createToken() string {
|
||||||
bytes := make([]byte, 64)
|
return shortuuid.New()
|
||||||
if _, err := rand.Read(bytes); err != nil {
|
|
||||||
return "", errors.Wrap(err, "error generating random api token")
|
|
||||||
}
|
|
||||||
return hex.EncodeToString(bytes), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomId() (string, error) {
|
func randomId() (string, error) {
|
||||||
|
1
go.mod
1
go.mod
@ -45,6 +45,7 @@ require (
|
|||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
|
github.com/lithammer/shortuuid/v4 v4.0.0 // indirect
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.12 // indirect
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -306,6 +306,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
|||||||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
|
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
|
||||||
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
|
github.com/lithammer/shortuuid/v4 v4.0.0 h1:QRbbVkfgNippHOS8PXDkti4NaWeyYfcBTHtw7k08o4c=
|
||||||
|
github.com/lithammer/shortuuid/v4 v4.0.0/go.mod h1:Zs8puNcrvf2rV9rTH51ZLLcj7ZXqQI3lv67aw4KiB1Y=
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||||
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||||
|
Loading…
Reference in New Issue
Block a user