Class: TrivialSso::Login
- Inherits:
-
Object
- Object
- TrivialSso::Login
- Defined in:
- lib/trivial_sso/login.rb
Class Method Summary collapse
-
.cookie(userdata, expire_date = default_expire_date) ⇒ Object
create an encrypted and signed cookie containing userdata and an expiry date.
-
.decode_cookie(cookie = nil) ⇒ Object
Decodes and verifies an encrypted cookie throw a proper exception if a bad or invalid cookie.
Class Method Details
.cookie(userdata, expire_date = default_expire_date) ⇒ Object
create an encrypted and signed cookie containing userdata and an expiry date. userdata should be an array, and at minimum include a ‘username’ key. using json serializer to hopefully allow future cross version compatibliity (Marshall, the default serializer, is not compatble between versions)
28 29 30 31 32 33 34 35 36 |
# File 'lib/trivial_sso/login.rb', line 28 def self.(userdata, expire_date = default_expire_date) begin raise TrivialSso::Error::MissingConfig if sso_secret raise TrivialSso::Error::NoUsernameCookie if check_username(userdata) enc.encrypt_and_sign([userdata, expire_date]) rescue NoMethodError raise TrivialSso::Error::MissingConfig end end |
.decode_cookie(cookie = nil) ⇒ Object
Decodes and verifies an encrypted cookie throw a proper exception if a bad or invalid cookie. otherwise, return the username and userdata stored in the cookie
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/trivial_sso/login.rb', line 10 def self.( = nil) begin raise TrivialSso::Error::MissingCookie if .nil? || .empty? userdata, = .decrypt_and_verify() raise TrivialSso::Error::LoginExpired if () userdata rescue NoMethodError raise TrivialSso::Error::MissingConfig rescue ActiveSupport::MessageVerifier::InvalidSignature || ActiveSupport::MessageEncryptor::InvalidMessage raise TrivialSso::Error::BadCookie end end |