Skip to content

Commit

Permalink
Refactor code to use the new utilities module
Browse files Browse the repository at this point in the history
  • Loading branch information
David Kosub committed Jan 6, 2015
1 parent 170734b commit 9f44d29
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
20 changes: 5 additions & 15 deletions src/hmac-sha1.coffee
@@ -1,16 +1,6 @@
crypto = require('crypto')
crypto = require 'crypto'
url = require 'url'



# Special encode is our encoding method that implements
# the encoding of characters not defaulted by encodeURI
#
# Specifically ' and !
#
# Returns the encoded string
special_encode = (string) ->
encodeURIComponent(string).replace(/[!'()]/g, escape).replace(/\*/g, '%2A')
utils = require './utils'


# Cleaning invloves:
Expand All @@ -26,7 +16,7 @@ _clean_request_body = (body, query) ->
out = []

encodeParam = (key, val) ->
return "#{key}=#{special_encode(val)}"
return "#{key}=#{utils.special_encode(val)}"

cleanParams = (params) ->
return if typeof params isnt 'object'
Expand All @@ -44,7 +34,7 @@ _clean_request_body = (body, query) ->
cleanParams body
cleanParams query

special_encode out.sort().join('&')
utils.special_encode out.sort().join('&')



Expand All @@ -56,7 +46,7 @@ class HMAC_SHA1
build_signature_raw: (req_url, parsed_url, method, params, consumer_secret, token) ->
sig = [
method.toUpperCase()
special_encode req_url
utils.special_encode req_url
_clean_request_body params, parsed_url.query
]

Expand Down
3 changes: 2 additions & 1 deletion src/outcome-service.coffee
Expand Up @@ -9,6 +9,7 @@ xml2js = require 'xml2js'
xml_builder = require 'xmlbuilder'

errors = require './errors'
utils = require './utils'



Expand Down Expand Up @@ -144,7 +145,7 @@ class OutcomeService

headers.oauth_signature = @provider.signer.build_signature_raw @service_url_oauth, @service_url_parts, 'POST', headers, @provider.consumer_secret

Authorization: 'OAuth realm="",' + ("#{key}=\"#{encodeURIComponent(val)}\"" for key, val of headers).join ','
Authorization: 'OAuth realm="",' + ("#{key}=\"#{utils.special_encode(val)}\"" for key, val of headers).join ','
'Content-Type': 'application/xml'
'Content-Length': body.length

Expand Down

0 comments on commit 9f44d29

Please sign in to comment.