@@ -15,7 +15,7 @@ import (
15
15
16
16
type contextKey string
17
17
18
- const claimsKey contextKey = "claims "
18
+ const claimsKey contextKey = "githubClaims "
19
19
20
20
const githubKeysURL = "https://token.actions.githubusercontent.com/.well-known/jwks"
21
21
@@ -73,10 +73,12 @@ func JWTAuthMiddleware(next http.Handler) http.Handler {
73
73
})
74
74
}
75
75
76
- func verifyJWT (tokenString string ) (* GitHubClaims , error ) {
76
+ func verifyJWT (tokenString string ) (GitHubClaims , error ) {
77
+ var claims GitHubClaims
78
+
77
79
keySet , err := fetchJWKS ()
78
80
if err != nil {
79
- return nil , fmt .Errorf ("Unable to fetch JWKS: %v" , err )
81
+ return claims , fmt .Errorf ("Unable to fetch JWKS: %v" , err )
80
82
}
81
83
82
84
ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Second )
@@ -88,23 +90,22 @@ func verifyJWT(tokenString string) (*GitHubClaims, error) {
88
90
jwt .WithContext (ctx ),
89
91
jwt .WithVerify (true ))
90
92
if err != nil {
91
- return nil , fmt .Errorf ("Unable to parse token: %v" , err )
93
+ return claims , fmt .Errorf ("Unable to parse token: %v" , err )
92
94
}
93
95
94
96
if err := validateClaims (token ); err != nil {
95
- return nil , fmt .Errorf ("Unable to validate claims: %v" , err )
97
+ return claims , fmt .Errorf ("Unable to validate claims: %v" , err )
96
98
}
97
99
rawClaims , err := json .Marshal (token )
98
100
if err != nil {
99
- return nil , fmt .Errorf ("failed to marshal claims: %v" , err )
101
+ return claims , fmt .Errorf ("failed to marshal claims: %v" , err )
100
102
}
101
103
102
- var claims GitHubClaims
103
104
if err := json .Unmarshal (rawClaims , & claims ); err != nil {
104
- return nil , fmt .Errorf ("failed to unmarshal claims: %v" , err )
105
+ return claims , fmt .Errorf ("failed to unmarshal claims: %v" , err )
105
106
}
106
107
107
- return & claims , nil
108
+ return claims , nil
108
109
}
109
110
110
111
func fetchJWKS () (jwk.Set , error ) {
0 commit comments