Skip to content

Commit

Permalink
Merge pull request #5 from wbhumphrey/master
Browse files Browse the repository at this point in the history
Allow apps to generate a signatureBase directly
  • Loading branch information
ribrdb authored Mar 24, 2020
2 parents 5847673 + 8eea437 commit 880c0bf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions auther.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (a *auther) setRequestTokenAuthHeader(req *http.Request) error {
oauthParams[oauthBodyHash] = bodyHash
}

signatureBase := signatureBase(req, params)
signatureBase := SignatureBase(req, params)
signature, err := a.signer().Sign("", signatureBase)
if err != nil {
return err
Expand Down Expand Up @@ -102,7 +102,7 @@ func (a *auther) setAccessTokenAuthHeader(req *http.Request, requestToken, reque
oauthParams[oauthBodyHash] = bodyHash
}

signatureBase := signatureBase(req, params)
signatureBase := SignatureBase(req, params)
signature, err := a.signer().Sign(requestSecret, signatureBase)
if err != nil {
return err
Expand All @@ -129,7 +129,7 @@ func (a *auther) setRequestAuthHeader(req *http.Request, accessToken *Token) err
return err
}

signatureBase := signatureBase(req, params)
signatureBase := SignatureBase(req, params)
signature, err := a.signer().Sign(tokenSecret, signatureBase)
if err != nil {
return err
Expand Down Expand Up @@ -275,10 +275,10 @@ func collectParameters(req *http.Request, oauthParams map[string]string) (map[st
return params, nil
}

// signatureBase combines the uppercase request method, percent encoded base
// SignatureBase combines the uppercase request method, percent encoded base
// string URI, and normalizes the request parameters int a parameter string.
// Returns the OAuth1 signature base string according to RFC5849 3.4.1.
func signatureBase(req *http.Request, params map[string]string) string {
func SignatureBase(req *http.Request, params map[string]string) string {
method := strings.ToUpper(req.Method)
baseURL := baseURI(req)
parameterString := normalizedParameterString(params)
Expand Down
2 changes: 1 addition & 1 deletion auther_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestSignatureBase(t *testing.T) {
}
// assert that method is uppercased, base uri rules applied, queries added, joined by &
for _, c := range cases {
base := signatureBase(c.req, c.params)
base := SignatureBase(c.req, c.params)
assert.Equal(t, c.signatureBase, base)
}
}
Expand Down
2 changes: 1 addition & 1 deletion reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestTwitterSignatureBase(t *testing.T) {
oauthParams := auther.commonOAuthParams()
oauthParams[oauthTokenParam] = expectedTwitterOAuthToken
params, err := collectParameters(req, oauthParams)
signatureBase := signatureBase(req, params)
signatureBase := SignatureBase(req, params)
// assert that the signature base string matches the reference
// checks that method is uppercased, url is encoded, parameter string is added, all joined by &
expectedSignatureBase := "POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521"
Expand Down
2 changes: 1 addition & 1 deletion validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (r providerRequest) checkSignature(signer Signer) error {
if signer == nil {
return errSignatureMismatch
}
base := signatureBase(r.req, r.oauthParams)
base := SignatureBase(r.req, r.oauthParams)
signature, err := signer.Sign("", base)
if err != nil {
return err
Expand Down

0 comments on commit 880c0bf

Please sign in to comment.