Documentation ¶
Overview ¶
The package implements the xero.Authorizer interface using the https://github.com/garyburd/go-oauth library.
Example ¶
package main import ( "crypto/x509" "encoding/pem" "io/ioutil" "log" "net/http" oauth "github.com/thisissoon/go-xero/authorizers/go-oauth" ) func main() { f, err := ioutil.ReadFile("/path/to/pem") if err != nil { log.Fatal(err) } block, extra := pem.Decode(f) if block == nil || len(extra) > 0 { log.Fatal("failed to decode PEM") } pk, err := x509.ParsePKCS1PrivateKey(block.Bytes) if err != nil { log.Fatal(err) } authorizer := oauth.New("TOKEN", pk) req, err := http.NewRequest( http.MethodGet, "https://api.xero.com/api.xro/2.0/Invoices", nil) if err != nil { log.Fatal(err) } if err := authorizer.AuthorizeRequest(req); err != nil { log.Fatal(err) } rsp, err := http.DefaultClient.Do(req) if err != nil { log.Fatal(err) } defer rsp.Body.Close() log.Println(rsp.Status) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
The Authorizer type provides a wrapper to the github.com/garyburd/go-oauth/oauth that fullfills the xero.Authorizer interface for authorizing xero API requests
func (*Authorizer) AuthorizeRequest ¶
func (a *Authorizer) AuthorizeRequest(req *http.Request) error
AuthorizeRequest fullfills the xero.Authorizer interface, authorizing a HTTP request
Click to show internal directories.
Click to hide internal directories.