Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Reduce account jwt token validity to 30mins

Neeraj Guptac95260a22872
diff --git a/server/pkg/controller/user/jwt.go b/server/pkg/controller/user/jwt.go
index d920e36b0b..a3d02b2eff 100644
--- a/server/pkg/controller/user/jwt.go
+++ b/server/pkg/controller/user/jwt.go
@@ -13,11 +13,15 @@ import (
const ValidForDays = 1
func (c *UserController) GetJWTToken(userID int64, scope enteJWT.ClaimScope) (string, error) {
+ tokenExpirty := time.NDaysFromNow(1)
+ if scope == enteJWT.ACCOUNTS {
+ tokenExpirty = time.NMinFromNow(30)
+ }
// Create a new token object, specifying signing method and the claims
// you would like it to contain.
token := jwt.NewWithClaims(jwt.SigningMethodHS256, &enteJWT.WebCommonJWTClaim{
UserID: userID,
- ExpiryTime: time.NDaysFromNow(1),
+ ExpiryTime: tokenExpirty,
ClaimScope: &scope,
})
// Sign and get the complete encoded token as a string using the secret
diff --git a/server/pkg/utils/time/time.go b/server/pkg/utils/time/time.go
index c03f97696d..a07df4b262 100644
--- a/server/pkg/utils/time/time.go
+++ b/server/pkg/utils/time/time.go
@@ -48,6 +48,11 @@ func NDaysFromNow(n int) int64 {
return time.Now().AddDate(0, 0, n).UnixNano() / 1000
}
+// NMinFromNow returns the time n min from now in micro seconds
+func NMinFromNow(n int64) int64 {
+ return time.Now().Add(time.Minute*time.Duration(n)).UnixNano() / 1000
+}
+
// MicrosecondsBeforeMinutes returns the unix time n minutes before now in micro seconds
func MicrosecondsBeforeMinutes(noOfMinutes int64) int64 {
return Microseconds() - (MicroSecondsInOneMinute * noOfMinutes)