diff options
author | Mura Li <typeless@users.noreply.github.com> | 2019-03-27 19:15:23 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-03-27 19:15:23 +0800 |
commit | d77176912bccf1dc0ad93366df55f00fee23b498 (patch) | |
tree | 309fc6350f77f4061360160b88343360d45d5d24 /vendor/github.com/mrjones | |
parent | d578b71d61ee8131e8abf7f538b93d8c6cc6fe6d (diff) | |
download | gitea-d77176912bccf1dc0ad93366df55f00fee23b498.tar.gz gitea-d77176912bccf1dc0ad93366df55f00fee23b498.zip |
Use Go1.11 module (#5743)
* Migrate to go modules
* make vendor
* Update mvdan.cc/xurls
* make vendor
* Update code.gitea.io/git
* make fmt-check
* Update github.com/go-sql-driver/mysql
* make vendor
Diffstat (limited to 'vendor/github.com/mrjones')
-rw-r--r-- | vendor/github.com/mrjones/oauth/MIT-LICENSE.txt | 7 | ||||
-rw-r--r-- | vendor/github.com/mrjones/oauth/README.md | 51 | ||||
-rw-r--r-- | vendor/github.com/mrjones/oauth/oauth.go | 54 | ||||
-rw-r--r-- | vendor/github.com/mrjones/oauth/pre-commit.sh | 21 |
4 files changed, 113 insertions, 20 deletions
diff --git a/vendor/github.com/mrjones/oauth/MIT-LICENSE.txt b/vendor/github.com/mrjones/oauth/MIT-LICENSE.txt new file mode 100644 index 0000000000..6c9461e6c6 --- /dev/null +++ b/vendor/github.com/mrjones/oauth/MIT-LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (C) 2013 Matthew R. Jones + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/mrjones/oauth/README.md b/vendor/github.com/mrjones/oauth/README.md new file mode 100644 index 0000000000..c0f7eb5479 --- /dev/null +++ b/vendor/github.com/mrjones/oauth/README.md @@ -0,0 +1,51 @@ +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) + +[![CircleCI](https://circleci.com/gh/mrjones/oauth/tree/master.svg?style=svg)](https://circleci.com/gh/mrjones/oauth/tree/master) + +(If you need an OAuth 2.0 library, check out: https://godoc.org/golang.org/x/oauth2) + +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 + + + + diff --git a/vendor/github.com/mrjones/oauth/oauth.go b/vendor/github.com/mrjones/oauth/oauth.go index 95eee64abd..f16edb83dd 100644 --- a/vendor/github.com/mrjones/oauth/oauth.go +++ b/vendor/github.com/mrjones/oauth/oauth.go @@ -142,7 +142,7 @@ type ServiceProvider struct { // Allow parameters to be passed in the query string rather // than the body. // See https://github.com/mrjones/oauth/pull/63 - SignQueryParams bool + SignQueryParams bool } func (sp *ServiceProvider) httpMethod() string { @@ -451,8 +451,10 @@ func (c *Consumer) AuthorizeToken(rtoken *RequestToken, verificationCode string) func (c *Consumer) AuthorizeTokenWithParams(rtoken *RequestToken, verificationCode string, additionalParams map[string]string) (atoken *AccessToken, err error) { params := map[string]string{ - VERIFIER_PARAM: verificationCode, - TOKEN_PARAM: rtoken.Token, + TOKEN_PARAM: rtoken.Token, + } + if verificationCode != "" { + params[VERIFIER_PARAM] = verificationCode } return c.makeAccessTokenRequestWithParams(params, rtoken.Secret, additionalParams) } @@ -674,8 +676,12 @@ func (c *Consumer) makeAuthorizedRequestReader(method string, urlString string, } else { // TODO(mrjones): validate that we're not overrideing an exising body? - request.Body = ioutil.NopCloser(strings.NewReader(vals.Encode())) request.ContentLength = int64(len(vals.Encode())) + if request.ContentLength == 0 { + request.Body = nil + } else { + request.Body = ioutil.NopCloser(strings.NewReader(vals.Encode())) + } } for k, vs := range c.AdditionalHeaders { @@ -781,6 +787,25 @@ func canonicalizeUrl(u *url.URL) string { return buf.String() } +func getBody(request *http.Request) ([]byte, error) { + if request.Body == nil { + return nil, nil + } + defer request.Body.Close() + originalBody, err := ioutil.ReadAll(request.Body) + if err != nil { + return nil, err + } + + // We have to re-install the body (because we've ruined it by reading it). + if len(originalBody) > 0 { + request.Body = ioutil.NopCloser(bytes.NewReader(originalBody)) + } else { + request.Body = nil + } + return originalBody, nil +} + func parseBody(request *http.Request) (map[string]string, error) { userParams := map[string]string{} @@ -797,17 +822,12 @@ func parseBody(request *http.Request) (map[string]string, error) { } } else { // x-www-form-urlencoded parameters come from the body instead: - defer request.Body.Close() - originalBody, err := ioutil.ReadAll(request.Body) + body, err := getBody(request) if err != nil { return nil, err } - // If there was a body, we have to re-install it - // (because we've ruined it by reading it). - request.Body = ioutil.NopCloser(bytes.NewReader(originalBody)) - - params, err := url.ParseQuery(string(originalBody)) + params, err := url.ParseQuery(string(body)) if err != nil { return nil, err } @@ -843,24 +863,18 @@ func calculateBodyHash(request *http.Request, s signer) (string, error) { return "", nil } - var originalBody []byte + var body []byte if request.Body != nil { var err error - - defer request.Body.Close() - originalBody, err = ioutil.ReadAll(request.Body) + body, err = getBody(request) if err != nil { return "", err } - - // If there was a body, we have to re-install it - // (because we've ruined it by reading it). - request.Body = ioutil.NopCloser(bytes.NewReader(originalBody)) } h := s.HashFunc().New() - h.Write(originalBody) + h.Write(body) rawSignature := h.Sum(nil) return base64.StdEncoding.EncodeToString(rawSignature), nil diff --git a/vendor/github.com/mrjones/oauth/pre-commit.sh b/vendor/github.com/mrjones/oauth/pre-commit.sh new file mode 100644 index 0000000000..91b9e88236 --- /dev/null +++ b/vendor/github.com/mrjones/oauth/pre-commit.sh @@ -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 |