Skip to content

Commit ec0b637

Browse files
committed
remove expiration and stuff
1 parent d3aaf8d commit ec0b637

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

main.go

+5-22
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,36 @@
11
package main
22

33
import (
4-
"fmt"
54
"log"
65
"os"
76
"path/filepath"
87

9-
"encoding/base64"
10-
118
"github.com/lugvitc/staticfs/middleware"
129

1310
"github.com/gin-gonic/gin"
1411
"github.com/joho/godotenv"
1512
)
1613

17-
func loadSecretKey() ([]byte, error) {
18-
secretKey := os.Getenv("JWT_SECRET")
19-
if secretKey == "" {
20-
return nil, fmt.Errorf("PUBLIC_KEY environment variable not set")
21-
}
22-
return base64.StdEncoding.DecodeString(secretKey)
23-
}
24-
2514
func main() {
2615
err := godotenv.Load()
2716
if err != nil {
28-
log.Fatal("Error loading .env file")
17+
log.Fatalln("Error loading .env file")
2918
}
3019
dataDir := os.Getenv("DATA_DIR")
3120
r := gin.Default()
32-
secretKey, err := loadSecretKey()
33-
if err != nil {
34-
log.Fatalf("Error loading public key: %v", err)
21+
secretKey := os.Getenv("JWT_SECRET")
22+
if secretKey == "" {
23+
log.Fatalln("JWT_SECRET environment variable not set")
3524
}
36-
r.Use(middleware.AuthMiddleware(secretKey))
25+
r.Use(middleware.AuthMiddleware([]byte(secretKey)))
3726
r.GET("/*filepath", func(c *gin.Context) {
3827
teamID := c.MustGet("teamId").(string)
3928
containerID := c.MustGet("containerId").(string)
4029
requestedFile := c.Param("filepath")
4130

4231
// Clean the file path to prevent directory traversal attacks.
4332
fullPath := filepath.Join(dataDir, teamID, containerID, filepath.Clean(requestedFile))
44-
// fmt.Println(fullPath)
4533
c.File(fullPath)
4634
})
47-
// token, err := utils.CreateJWT("randomteam123", "randomcontainer123", secretKey)
48-
// if err != nil {
49-
// log.Fatalf("Failed to generate JWT: %v", err)
50-
// }
51-
// fmt.Println("Generated JWT:", token)
5235
r.Run()
5336
}

utils/jwt.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package utils
22

33
import (
44
"fmt"
5+
56
"github.com/golang-jwt/jwt/v5"
6-
"time"
77
)
88

99
type TeamClaims struct {
@@ -13,13 +13,9 @@ type TeamClaims struct {
1313
}
1414

1515
func CreateJWT(teamId, containerId string, secretKey []byte) (string, error) {
16-
expirationTime := time.Now().Add(time.Hour)
1716
claims := jwt.NewWithClaims(jwt.SigningMethodHS256, TeamClaims{
1817
Id: teamId,
1918
ContainerId: containerId,
20-
RegisteredClaims: jwt.RegisteredClaims{
21-
ExpiresAt: jwt.NewNumericDate(expirationTime),
22-
},
2319
})
2420
tokenString, err := claims.SignedString(secretKey)
2521
if err != nil {

0 commit comments

Comments
 (0)