oauth

package
v0.0.0-...-8519e09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2017 License: MIT Imports: 5 Imported by: 0

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 New

func New(token string, pk *rsa.PrivateKey) *Authorizer

New constructs a new Authorizer

func (*Authorizer) AuthorizeRequest

func (a *Authorizer) AuthorizeRequest(req *http.Request) error

AuthorizeRequest fullfills the xero.Authorizer interface, authorizing a HTTP request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL