diff --git a/auth/oauth.go b/auth/oauth.go index e428b77f6613b3ad5136b089c79ac52033266efa..b03c1efb7e4918bca48f1a327eede4fc4d1c20ed 100644 --- a/auth/oauth.go +++ b/auth/oauth.go @@ -1,10 +1,8 @@ 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)