This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (66 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"crypto/rsa"
"fmt"
"io/ioutil"
"os"
"time"
"github.com/golang-jwt/jwt/v4"
"lockbox.dev/sessions"
)
func pathOrContents(in string) (string, error) {
if _, err := os.Stat(in); err == nil {
contents, err := ioutil.ReadFile(in)
if err != nil {
return string(contents), err
}
return string(contents), nil
}
return in, nil
}
func main() {
key := os.Getenv("JWT_KEY")
if key == "" {
fmt.Println("JWT_KEY must be specified")
os.Exit(1)
}
privateKeyStr, err := pathOrContents(key)
if err != nil {
fmt.Println("Error getting JWT_KEY contents:", err)
os.Exit(1)
}
privateKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(privateKeyStr))
if err != nil {
fmt.Println("Error parsing JWT_KEY contents:", err)
os.Exit(1)
}
serviceID := os.Getenv("SERVICE")
if serviceID == "" {
fmt.Println("SERVICE must be specified")
os.Exit(1)
}
if len(os.Args) < 2 {
fmt.Println("Usage: ./spoof PROFILE_ID")
os.Exit(1)
}
profile := os.Args[1]
deps := sessions.Dependencies{
JWTPrivateKey: privateKey,
JWTPublicKey: privateKey.Public().(*rsa.PublicKey),
ServiceID: serviceID,
}
token := sessions.AccessToken{
ID: "spoof",
CreatedFrom: "spoof",
ProfileID: profile,
ClientID: "spoof",
CreatedAt: time.Now(),
}
jwt, err := deps.CreateJWT(context.Background(), token)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
fmt.Println(jwt)
}