ezOauth1

package module
v0.0.0-...-5b7b127 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: MIT Imports: 8 Imported by: 0

README

ezOAuth1

__ Fork form : https://github.com/klaidas/go-oauth1 __
Golang lightweight package/ implementation example of OAuth1.0 Authentication Header/ Signature calculation (Twitter, CardMarked, ...)

To quickly import the package into your project:

 go get github.com/FOXCraft40/oauth1

 

Example usage:

package main

import (
	"fmt"
	"net/http"

	"github.com/FOXCraft40/oauth1"
)

func main() {
	method := http.MethodPost
	url := "https://api.twitter.com/1.1/statuses/update.json?include_entities=true"
	
	auth := oauth1.OAuth1{
		ConsumerKey: "xvz1evFS4wEEPTGEFPHBog",
		ConsumerSecret: "kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw",
		AccessToken: "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
		AccessSecret: "LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE",
	}

	authHeader := auth.BuildOAuth1Header(method, url, false, map[string]string {
		"include_entities": "true",
		"status": "Hello Ladies + Gentlemen, a signed OAuth request!",
	})
	
	req, _ := http.NewRequest(method, url, nil)
	req.Header.Set("Authorization", authHeader)
	
	if res, err := http.DefaultClient.Do(req); err == nil {
		fmt.Println(res.StatusCode)
	}
}

 

  • Simply import the package
  • Create an OAuth1 Object with the information you have (In some cases, AccessSecret will be unknown, this is fine)
  • Call BuildOAuth1Header to generate your Authorization Header for the request you're making

 

Output:

OAuth oauth_consumer_key="xvz1evFS4wEEPTGEFPHBog",oauth_token="370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1318622958",oauth_nonce="kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",oauth_version="1.0",oauth_signature="hCtSmYh%2BiHYCEqBWrE7C7hYmtUk%3D"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OAuth1

type OAuth1 struct {
	ConsumerKey    string
	ConsumerSecret string
	AccessToken    string
	AccessSecret   string
}

OAuth1 //

func (OAuth1) BuildOAuth1Header

func (auth OAuth1) BuildOAuth1Header(method, path string, withRealm bool, params map[string]string) string

BuildOAuth1Header // Params being any key-value url query parameter pairs

Jump to

Keyboard shortcuts

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