Using vendor for the oauth lib

This commit is contained in:
Joachim Hill-Grannec 2016-04-19 15:46:27 -07:00
parent c250926460
commit ef4d41c710
6 changed files with 1612 additions and 1 deletions

View file

@ -12,7 +12,6 @@ deps:
go get -u github.com/elazarl/go-bindata-assetfs/...
go get -u github.com/dchest/jsmin
go get -u github.com/franela/goblin
go get -u github.com/mrjones/oauth
gen: gen_static gen_template gen_migrations

49
vendor/github.com/mrjones/oauth/README.md generated vendored Normal file
View file

@ -0,0 +1,49 @@
OAuth 1.0 Library for [Go](http://golang.org)
========================
[![GoDoc](http://godoc.org/github.com/mrjones/oauth?status.png)](http://godoc.org/github.com/mrjones/oauth)
(If you need an OAuth 2.0 library, check out: http://code.google.com/p/goauth2/)
Developing your own apps, with this library
-------------------------------------------
* First, install the library
go get github.com/mrjones/oauth
* Then, check out the comments in oauth.go
* Or, have a look at the examples:
* Netflix
go run examples/netflix/netflix.go --consumerkey [key] --consumersecret [secret] --appname [appname]
* Twitter
Command line:
go run examples/twitter/twitter.go --consumerkey [key] --consumersecret [secret]
Or, in the browser (using an HTTP server):
go run examples/twitterserver/twitterserver.go --consumerkey [key] --consumersecret [secret] --port 8888
* The Google Latitude example is broken, now that Google uses OAuth 2.0
Contributing to this library
----------------------------
* Please install the pre-commit hook, which will run tests, and go-fmt before committing.
ln -s $PWD/pre-commit.sh .git/hooks/pre-commit
* Running tests and building is as you'd expect:
go test *.go
go build *.go

1389
vendor/github.com/mrjones/oauth/oauth.go generated vendored Normal file

File diff suppressed because it is too large Load diff

21
vendor/github.com/mrjones/oauth/pre-commit.sh generated vendored Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
# ln -s $PWD/pre-commit.sh .git/hooks/pre-commit
go test *.go
RESULT=$?
if [[ $RESULT != 0 ]]; then
echo "REJECTING COMMIT (test failed with status: $RESULT)"
exit 1;
fi
go fmt *.go
for e in $(ls examples); do
go build examples/$e/*.go
RESULT=$?
if [[ $RESULT != 0 ]]; then
echo "REJECTING COMMIT (Examples failed to compile)"
exit $RESULT;
fi
go fmt examples/$e/*.go
done
exit 0

147
vendor/github.com/mrjones/oauth/provider.go generated vendored Normal file
View file

@ -0,0 +1,147 @@
package oauth
import (
"bytes"
"fmt"
"math"
"net/http"
"net/url"
"strconv"
"strings"
)
//
// OAuth1 2-legged provider
// Contributed by https://github.com/jacobpgallagher
//
// Provide an buffer reader which implements the Close() interface
type oauthBufferReader struct {
*bytes.Buffer
}
// So that it implements the io.ReadCloser interface
func (m oauthBufferReader) Close() error { return nil }
type ConsumerGetter func(key string, header map[string]string) (*Consumer, error)
// Provider provides methods for a 2-legged Oauth1 provider
type Provider struct {
ConsumerGetter ConsumerGetter
// For mocking
clock clock
}
// NewProvider takes a function to get the consumer secret from a datastore.
// Returns a Provider
func NewProvider(secretGetter ConsumerGetter) *Provider {
provider := &Provider{
secretGetter,
&defaultClock{},
}
return provider
}
// Combine a URL and Request to make the URL absolute
func makeURLAbs(url *url.URL, request *http.Request) {
if !url.IsAbs() {
url.Host = request.Host
if request.TLS != nil || request.Header.Get("X-Forwarded-Proto") == "https" {
url.Scheme = "https"
} else {
url.Scheme = "http"
}
}
}
// IsAuthorized takes an *http.Request and returns a pointer to a string containing the consumer key,
// or nil if not authorized
func (provider *Provider) IsAuthorized(request *http.Request) (*string, error) {
var err error
var userParams map[string]string
// start with the body/query params
userParams, err = parseBody(request)
if err != nil {
return nil, err
}
// if the oauth params are in the Authorization header, grab them, and
// let them override what's in userParams
authHeader := request.Header.Get(HTTP_AUTH_HEADER)
if len(authHeader) > 6 && strings.EqualFold(OAUTH_HEADER, authHeader[0:6]) {
authHeader = authHeader[6:]
params := strings.Split(authHeader, ",")
for _, param := range params {
vals := strings.SplitN(param, "=", 2)
k := strings.Trim(vals[0], " ")
v := strings.Trim(strings.Trim(vals[1], "\""), " ")
if strings.HasPrefix(k, "oauth") {
userParams[k], err = url.QueryUnescape(v)
if err != nil {
return nil, err
}
}
}
}
// pop the request's signature, it's not included in our signature
// calculation
oauthSignature, ok := userParams[SIGNATURE_PARAM]
if !ok {
return nil, fmt.Errorf("no oauth signature")
}
delete(userParams, SIGNATURE_PARAM)
// Check the timestamp
oauthTimeNumber, err := strconv.Atoi(userParams[TIMESTAMP_PARAM])
if err != nil {
return nil, err
}
if math.Abs(float64(int64(oauthTimeNumber)-provider.clock.Seconds())) > 5*60 {
return nil, fmt.Errorf("too much clock skew")
}
// get the oauth consumer key
consumerKey, ok := userParams[CONSUMER_KEY_PARAM]
if !ok {
return nil, fmt.Errorf("no consumer key")
}
// use it to create a consumer object
consumer, err := provider.ConsumerGetter(consumerKey, userParams)
if err != nil {
return nil, err
}
// if our consumer supports bodyhash, check it
if consumer.serviceProvider.BodyHash {
bodyHash, err := calculateBodyHash(request, consumer.signer)
if err != nil {
return nil, err
}
sentHash, ok := userParams[BODY_HASH_PARAM]
if bodyHash == "" && ok {
return nil, fmt.Errorf("body_hash must not be set")
} else if sentHash != bodyHash {
return nil, fmt.Errorf("body_hash mismatch")
}
}
allParams := NewOrderedParams()
for key, value := range userParams {
allParams.Add(key, value)
}
makeURLAbs(request.URL, request)
baseString := consumer.requestString(request.Method, canonicalizeUrl(request.URL), allParams)
err = consumer.signer.Verify(baseString, oauthSignature)
if err != nil {
return nil, err
}
return &consumerKey, nil
}

6
vendor/vendor.json vendored
View file

@ -159,6 +159,12 @@
"revisionTime": "2016-03-07T18:57:06+09:00",
"tree": true
},
{
"checksumSHA1": "spRLFk8daizvEzOmRsxlxeECdHI=",
"path": "github.com/mrjones/oauth",
"revision": "31f1e8e5addda51bc50ebfc8bb930d4642372654",
"revisionTime": "2016-04-05T23:58:02Z"
},
{
"origin": "github.com/stretchr/testify/vendor/github.com/pmezard/go-difflib/difflib",
"path": "github.com/pmezard/go-difflib/difflib",