Admin APIs
The Admin API GraphQL endpoint
Accessing the Admin API GraphQL endpoint
Obtaining the private key for signing JWT
Generating the JWT with the private key
package main
import (
"encoding/json"
"fmt"
"os"
"time"
"github.com/lestrrat-go/jwx/jwa"
"github.com/lestrrat-go/jwx/jwk"
"github.com/lestrrat-go/jwx/jws"
"github.com/lestrrat-go/jwx/jwt"
)
// Replace "myapp" with your app ID here.
const AppID = "myapp"
// Replace "mykid" with the key ID you see in the portal.
const KeyID = "mykid"
func main() {
// Replace the following call with your own way to get the private key.
f, err := os.Open("private-key.pem")
if err != nil {
panic(err)
}
defer f.Close()
jwkSet, err := jwk.ParseReader(f, jwk.WithPEM(true))
if err != nil {
panic(err)
}
key, _ := jwkSet.Get(0)
now := time.Now().UTC()
payload := jwt.New()
_ = payload.Set(jwt.AudienceKey, AppID)
_ = payload.Set(jwt.IssuedAtKey, now.Unix())
_ = payload.Set(jwt.ExpirationKey, now.Add(5*time.Minute).Unix())
// The alg MUST be RS256.
alg := jwa.RS256
hdr := jws.NewHeaders()
hdr.Set("typ", "JWT")
hdr.Set("alg", alg.String())
hdr.Set("kid", KeyID)
buf, err := json.Marshal(payload)
if err != nil {
panic(err)
}
token, err := jws.Sign(buf, alg, key, jws.WithHeaders(hdr))
if err != nil {
panic(err)
}
fmt.Printf("%v\n", string(token))
}Including the JWT in the HTTP request
Optional: Caching the JWT
Trying out the Admin API GraphQL endpoint
Inspecting the GraphQL schema
Last updated