Class: RbSSO::Authentication
- Inherits:
-
Object
- Object
- RbSSO::Authentication
- Defined in:
- lib/rbsso/authentication.rb
Defined Under Namespace
Classes: VersionMismatch
Constant Summary collapse
- VERSION =
4
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#nonce ⇒ Object
readonly
Returns the value of attribute nonce.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #content ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(user:, service:, domain:, groups: [], nonce: nil, ttl: 3600, expires: nil) ⇒ Authentication
constructor
A new instance of Authentication.
- #to_info ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(user:, service:, domain:, groups: [], nonce: nil, ttl: 3600, expires: nil) ⇒ Authentication
Returns a new instance of Authentication.
13 14 15 16 17 |
# File 'lib/rbsso/authentication.rb', line 13 def initialize(user:, service:, domain:, groups: [], nonce: nil, ttl: 3600, expires: nil) @user, @service, @domain, @groups = user, service, domain, groups @nonce = nonce @expires = expires || (Time.now + ttl).to_i end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
11 12 13 |
# File 'lib/rbsso/authentication.rb', line 11 def domain @domain end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
11 12 13 |
# File 'lib/rbsso/authentication.rb', line 11 def expires @expires end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
11 12 13 |
# File 'lib/rbsso/authentication.rb', line 11 def groups @groups end |
#nonce ⇒ Object (readonly)
Returns the value of attribute nonce.
11 12 13 |
# File 'lib/rbsso/authentication.rb', line 11 def nonce @nonce end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
11 12 13 |
# File 'lib/rbsso/authentication.rb', line 11 def service @service end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
11 12 13 |
# File 'lib/rbsso/authentication.rb', line 11 def user @user end |
Class Method Details
.check_version(version) ⇒ Object
55 56 57 58 |
# File 'lib/rbsso/authentication.rb', line 55 def self.check_version(version) return if version.to_s == VERSION.to_s raise VersionMismatch.new(version) end |
.parse(string) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rbsso/authentication.rb', line 19 def self.parse(string) version, user, service, domain, expires, nonce, groups = string.split '|' check_version(version) new user: user, service: service, domain: domain, expires: expires.to_i, nonce: nonce, groups: (groups || '').split(',') end |
Instance Method Details
#==(other) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rbsso/authentication.rb', line 42 def ==(other) user == other.user && service == other.service && domain == other.domain && groups == other.groups && expires == other.expires && nonce == other.nonce end |
#content ⇒ Object
38 39 40 |
# File 'lib/rbsso/authentication.rb', line 38 def content [VERSION, user, service, domain, expires.to_s, nonce, groups.join(',')] end |
#expired? ⇒ Boolean
51 52 53 |
# File 'lib/rbsso/authentication.rb', line 51 def expired? self.expires < Time.now.to_i end |
#to_info ⇒ Object
34 35 36 |
# File 'lib/rbsso/authentication.rb', line 34 def to_info { name: user, email: user + '@' + domain } end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/rbsso/authentication.rb', line 30 def to_s content.join '|' end |