Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Auth

Golang library for exchanging IAM principal for a Twisp OIDC token.

Usage

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 Authorization and X-Twisp-Account-Id headers 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))
}

About

Golang client for Twisp

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages