-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ability to add signed timestamp to header #25
base: main
Are you sure you want to change the base?
Conversation
To do this you have to give the option to the *wsse_signature*! Like so: Savon.client({ … wsse_signature: Akami::WSSE::Signature.new( Akami::WSSE::Certs.new(…), timestamp: true) } It is also possible to give created_at and/or expires_at like this Savon.client({ … wsse_signature: Akami::WSSE::Signature.new( Akami::WSSE::Certs.new(…), {timestamp: true, created_at: Time.now-10, expires_at: Time.now + 600}) }
This would be extremely useful! |
Savon::Builder#build_document needs to create the headers 3 times instead of 2. I.e, replace "2.do" with "3.do" I do not yet know why. For some reason Signature#document needs to be mutated that many times. |
One can call build_document an extra time before initiating the request, or add this to lib/savon/builder.rb:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When implementing this code, I came across two issues. I have suggested solutions in my comments based on what I did to get the code to work.
@@ -151,6 +193,12 @@ def body_digest | |||
Base64.encode64(OpenSSL::Digest::SHA1.digest(body)).strip | |||
end | |||
|
|||
def timestamp_digest | |||
return nil unless timestamp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should tis be return nil unless self.timestamp
. It seems that timestamp
refers to the variable in the scope of the method due tot he assignment on the next line.
def timestamp_digest | ||
return nil unless timestamp | ||
timestamp = canonicalize(at_xpath(@document, "//Envelope/Header/Security/Timestamp")) | ||
Base64.encode64(OpenSSL::Digest::SHA1.digest(timestamp)).strip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if timestamp
is nil, which it can be, an exception is raised. Should this line be ended with ... if timestamp
?
To do this you have to give the timestamp-option to the wsse_signature!
Like so:
It is also possible to give created_at and/or expires_at like this