module GoInstant::Auth

Authentication classes and functions for use with GoInstant

Public Class Methods

compact_decode(str) click to toggle source

Decode the Compact Serialization of a thing. @param str [String] @return [Hash|String|Object]

# File lib/goinstant/auth.rb, line 40
def self.compact_decode(str)
  return JSON.parse(decode64(str))
end
compact_encode(thing) click to toggle source

Create a Compact Serialization of a thing. @param thing [Hash|String|Object] anything, passed to JSON.generate. @return [String]

# File lib/goinstant/auth.rb, line 47
def self.compact_encode(thing)
  return encode64(JSON.generate(thing))
end
decode64(str) click to toggle source

Decodes base64 and base64url encoded strings. @param str [String] @return [String]

# File lib/goinstant/auth.rb, line 32
def self.decode64(str)
  str = str.gsub(/\s+/,'').tr('-_','+/').sub(/=+$/,'')
  return Base64.decode64(pad64(str))
end
encode64(str) click to toggle source

Encodes base64 and base64url encoded strings. @param str [String] @return [String]

# File lib/goinstant/auth.rb, line 25
def self.encode64(str)
  return Base64.urlsafe_encode64(str).sub(/=+$/,'')
end
pad64(str) click to toggle source

Pads base64 strings. @param str [String] @return [String] padded (extra ‘=’ added to multiple of 4).

# File lib/goinstant/auth.rb, line 14
def self.pad64(str)
  rem = str.size % 4
  if rem > 0 then
    str << ("=" * (4-rem))
  end
  return str
end