lib/global_session/session.rb in global_session-1.0.6 vs lib/global_session/session.rb in global_session-1.0.7
- old
+ new
@@ -14,10 +14,21 @@
# it's expired, valid, supports a certain key, etc.
#
class Session
attr_reader :id, :authority, :created_at, :expired_at, :directory
+ # Utility method to decode a cookie; good for console debugging. This performs no
+ # validation or security check of any sort.
+ #
+ # === Parameters
+ # cookie(String):: well-formed global session cookie
+ def self.decode_cookie(cookie)
+ zbin = Encoding::Base64Cookie.load(cookie)
+ json = Zlib::Inflate.inflate(zbin)
+ return Encoding::JSON.load(json)
+ end
+
# Create a new global session object.
#
# === Parameters
# directory(Directory):: directory implementation that the session should use for various operations
# cookie(String):: Optional, serialized global session cookie. If none is supplied, a new session is created.
@@ -80,10 +91,10 @@
end
hash['dx'] = @insecure
hash['s'] = @signature
hash['a'] = authority
-
+
json = Encoding::JSON.dump(hash)
zbin = Zlib::Deflate.deflate(json, Zlib::BEST_COMPRESSION)
return Encoding::Base64Cookie.dump(zbin)
end