Golang library for exchanging IAM principal for a Twisp OIDC token.
Twisp provides an http.RoundTripper implementation that handles:
- Exchanging IAM principal for a Twisp OIDC token
- Auto-refreshing those tokens on expiration
- Automatically setting the
AuthorizationandX-Twisp-Account-Idheaders on HTTP requests
package main
import (
"fmt""io""log""net/http""strings""time""github.com/twisp/auth-go"
)
funcmain() {
var (
accountID="YourAccountID"region="us-west-2"api=fmt.Sprintf("https://api.%s.cloud.twisp.com/financial/v1/graphql", region)
)
client:=&http.Client{
Transport: auth.NewRoundTripper(accountID, region, http.DefaultTransport),
Timeout: time.Second*5,
}
query:=`{"query": "{ journal { code } }"}`req, err:=http.NewRequest(http.MethodPost, api, strings.NewReader(query))
iferr!=nil {
log.Fatal(err)
}
resp, err:=client.Do(req)
iferr!=nil {
log.Fatal(err)
}
deferresp.Body.Close()
out, err:=io.ReadAll(resp.Body)
iferr!=nil {
log.Fatal(err)
}
fmt.Printf("%s", string(out))
}