MCPcopy Index your code
hub / github.com/apache/devlake / createJWT

Function createJWT

backend/plugins/github/token/cmd/test_refresh/main.go:142–160  ·  view source on GitHub ↗
(appID, pemData string)

Source from the content-addressed store, hash-verified

140}
141
142func createJWT(appID, pemData string) (string, error) {
143 privateKey, err := jwt.ParseRSAPrivateKeyFromPEM([]byte(pemData))
144 if err != nil {
145 return "", fmt.Errorf("invalid PEM key: %w", err)
146 }
147
148 now := time.Now().Unix()
149 token := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
150 "iat": now,
151 "exp": now + (10 * 60), // 10 minutes
152 "iss": appID,
153 })
154
155 signed, err := token.SignedString(privateKey)
156 if err != nil {
157 return "", fmt.Errorf("failed to sign JWT: %w", err)
158 }
159 return signed, nil
160}
161
162func listInstallations(jwtToken string) ([]installation, error) {
163 req, err := http.NewRequest("GET", "https://api.github.com/app/installations", nil)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected