Add configurable invitation token validity
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
probod:
|
probod:
|
||||||
|
auth:
|
||||||
|
invitation-confirmation-token-validity: 3600
|
||||||
api:
|
api:
|
||||||
cors:
|
cors:
|
||||||
allowed-origins: ["http://localhost:8080", "http://localhost:5173"]
|
allowed-origins: ["http://localhost:8080", "http://localhost:5173"]
|
||||||
|
|||||||
@@ -21,9 +21,10 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
authConfig struct {
|
authConfig struct {
|
||||||
Cookie cookieConfig `json:"cookie"`
|
Cookie cookieConfig `json:"cookie"`
|
||||||
Password passwordConfig `json:"password"`
|
Password passwordConfig `json:"password"`
|
||||||
DisableSignup bool `json:"disable-signup"`
|
DisableSignup bool `json:"disable-signup"`
|
||||||
|
InvitationConfirmationTokenValidity int `json:"invitation-confirmation-token-validity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
trustAuthConfig struct {
|
trustAuthConfig struct {
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ func New() *Implm {
|
|||||||
Duration: 24,
|
Duration: 24,
|
||||||
Domain: "localhost",
|
Domain: "localhost",
|
||||||
},
|
},
|
||||||
DisableSignup: false,
|
DisableSignup: false,
|
||||||
|
InvitationConfirmationTokenValidity: 3600,
|
||||||
},
|
},
|
||||||
TrustAuth: trustAuthConfig{
|
TrustAuth: trustAuthConfig{
|
||||||
CookieName: "TCT",
|
CookieName: "TCT",
|
||||||
@@ -235,6 +236,7 @@ func (impl *Implm) Run(
|
|||||||
impl.cfg.Auth.Cookie.Secret,
|
impl.cfg.Auth.Cookie.Secret,
|
||||||
impl.cfg.Hostname,
|
impl.cfg.Hostname,
|
||||||
impl.cfg.Auth.DisableSignup,
|
impl.cfg.Auth.DisableSignup,
|
||||||
|
time.Duration(impl.cfg.Auth.InvitationConfirmationTokenValidity)*time.Second,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot create usrmgr service: %w", err)
|
return fmt.Errorf("cannot create usrmgr service: %w", err)
|
||||||
|
|||||||
@@ -32,11 +32,12 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Service struct {
|
Service struct {
|
||||||
pg *pg.Client
|
pg *pg.Client
|
||||||
hp *passwdhash.Profile
|
hp *passwdhash.Profile
|
||||||
hostname string
|
hostname string
|
||||||
tokenSecret string
|
tokenSecret string
|
||||||
disableSignup bool
|
disableSignup bool
|
||||||
|
invitationTokenValidity time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrInvalidCredentials struct {
|
ErrInvalidCredentials struct {
|
||||||
@@ -168,13 +169,15 @@ func NewService(
|
|||||||
tokenSecret string,
|
tokenSecret string,
|
||||||
hostname string,
|
hostname string,
|
||||||
disableSignup bool,
|
disableSignup bool,
|
||||||
|
invitationTokenValidity time.Duration,
|
||||||
) (*Service, error) {
|
) (*Service, error) {
|
||||||
return &Service{
|
return &Service{
|
||||||
pg: pgClient,
|
pg: pgClient,
|
||||||
hp: hp,
|
hp: hp,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
tokenSecret: tokenSecret,
|
tokenSecret: tokenSecret,
|
||||||
disableSignup: disableSignup,
|
disableSignup: disableSignup,
|
||||||
|
invitationTokenValidity: invitationTokenValidity,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,7 +713,7 @@ func (s Service) InviteUser(
|
|||||||
confirmationToken, err := statelesstoken.NewToken(
|
confirmationToken, err := statelesstoken.NewToken(
|
||||||
s.tokenSecret,
|
s.tokenSecret,
|
||||||
TokenTypeOrganizationInvitation,
|
TokenTypeOrganizationInvitation,
|
||||||
12*time.Hour,
|
s.invitationTokenValidity,
|
||||||
InvitationData{OrganizationID: organizationID, Email: emailAddress, FullName: fullName},
|
InvitationData{OrganizationID: organizationID, Email: emailAddress, FullName: fullName},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user