Method: FacebookClient::Session::SignedRequestParam.base64_url_decode
- Defined in:
- lib/session/signed_request_param.rb
.base64_url_decode(str) ⇒ Object
Ruby’s implementation of base64 decoding seems to be reading the string in multiples of 4 and ignoring any extra characters if there are no white-space characters at the end. Since facebook does not take this into account, this function fills any string with white spaces up to the point where it becomes divisible by 4, then it replaces ‘-’ with ‘+’ and ‘_’ with ‘/’ (URL-safe decoding), and decodes the result.
83 84 85 86 |
# File 'lib/session/signed_request_param.rb', line 83 def self.base64_url_decode(str) str = str + "=" * (4 - str.size % 4) unless str.size % 4 == 0 return Base64.decode64(str.tr("-_", "+/")) end |