-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
42 lines (38 loc) · 919 Bytes
/
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
package main
import (
"fmt"
"io/ioutil"
"github.com/coccodrillo/s3imageserver/s3imageserver"
"github.com/dgrijalva/jwt-go"
)
func main() {
s3imageserver.Run(nil)
}
func verifyToken(tokenString string) bool {
publicKey, err := ioutil.ReadFile("verification.key")
if err != nil {
fmt.Print("Error:", err)
return false
}
_, err = jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
return publicKey, nil
})
if err != nil {
errType := err.(*jwt.ValidationError)
switch errType.Errors {
case jwt.ValidationErrorMalformed:
fmt.Println("malformed")
case jwt.ValidationErrorUnverifiable:
fmt.Println("unverifiable")
case jwt.ValidationErrorSignatureInvalid:
fmt.Println("signature invalid")
case jwt.ValidationErrorExpired:
fmt.Println("expired")
case jwt.ValidationErrorNotValidYet:
fmt.Println("not valid yet")
}
} else {
return true
}
return false
}