Skip to content
Snippets Groups Projects
Commit 36913fa5 authored by Billy Griffiths's avatar Billy Griffiths
Browse files

use the existing SHA265 hash function

parent 9b2d1785
No related branches found
No related tags found
1 merge request!38Add OAuth1.0 header generation
package oauth
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"github.com/aws/aws-sdk-go/aws"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/encryption"
"math/rand"
"net/url"
"strconv"
......@@ -55,7 +53,7 @@ func (auth Oauth1) GenerateAuthorizationHeader(method, requestUrl string) (Autho
// Build the signature
signatureBase := strings.ToUpper(method) + "&" + url.QueryEscape(strings.Split(requestUrl, "?")[0]) + "&" + url.QueryEscape(parameterString)
signingKey := url.QueryEscape(auth.ConsumerSecret) + "&" + url.QueryEscape(auth.AccessSecret)
signature := calculateSignature(signatureBase, signingKey)
signature := encryption.Hash(signatureBase, signingKey)
// Populate all the authorisation parameters
authParams := map[string]string{
......@@ -77,13 +75,6 @@ func (auth Oauth1) GenerateAuthorizationHeader(method, requestUrl string) (Autho
return aws.String("OAuth " + strings.TrimSuffix(AuthorizationString, ",")), nil
}
func calculateSignature(base, key string) string {
hash := hmac.New(sha256.New, []byte(key))
hash.Write([]byte(base))
signature := hash.Sum(nil)
return base64.StdEncoding.EncodeToString(signature)
}
func generateNonce() string {
const allowed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
b := make([]byte, 48)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment