-
Notifications
You must be signed in to change notification settings - Fork 1
/
attestations.go
45 lines (34 loc) · 1.14 KB
/
attestations.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
package vessel
import (
"net/http"
"github.com/golang-jwt/jwt"
)
// This function verifies the validity of a given vessel attestation token and if valid returns the embedded
// attestation data field back to the caller
func GetAttestation(req *http.Request, owner string, tokenName string) string {
// Extract the web3 auth token from the web3auth cookie value if present
cookie, err := req.Cookie(tokenName)
if err != nil || cookie == nil {
return ""
}
web3Token := cookie.Value
// Initialize a new instance of `Claims`
parseclaims := &VesselClaims{}
// Lets do a test parse against the public key to make sure we've issued a valid attestation token
tkn, err := jwt.ParseWithClaims(web3Token, parseclaims, func(token *jwt.Token) (interface{}, error) {
return gVesselPublicKey, nil
})
// Sanity check for errors
if err != nil {
return ""
}
// Sanity check the token is actually valid
if !tkn.Valid {
return ""
}
// Finally verify the attestation token is issued to the correct owner
if parseclaims.StandardClaims.Subject != owner {
return ""
}
return parseclaims.AttestationData
}