Class: RbSSO::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/rbsso/authentication.rb

Defined Under Namespace

Classes: VersionMismatch

Constant Summary collapse

VERSION =
4

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#domainObject (readonly)

Returns the value of attribute domain.



11
12
13
# File 'lib/rbsso/authentication.rb', line 11

def domain
  @domain
end

#expiresObject (readonly)

Returns the value of attribute expires.



11
12
13
# File 'lib/rbsso/authentication.rb', line 11

def expires
  @expires
end

#groupsObject (readonly)

Returns the value of attribute groups.



11
12
13
# File 'lib/rbsso/authentication.rb', line 11

def groups
  @groups
end

#nonceObject (readonly)

Returns the value of attribute nonce.



11
12
13
# File 'lib/rbsso/authentication.rb', line 11

def nonce
  @nonce
end

#serviceObject (readonly)

Returns the value of attribute service.



11
12
13
# File 'lib/rbsso/authentication.rb', line 11

def service
  @service
end

#userObject (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

Raises:



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

#contentObject



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

Returns:

  • (Boolean)


51
52
53
# File 'lib/rbsso/authentication.rb', line 51

def expired?
  self.expires < Time.now.to_i
end

#to_infoObject



34
35
36
# File 'lib/rbsso/authentication.rb', line 34

def to_info
  { name: user, email: user + '@' + domain }
end

#to_sObject



30
31
32
# File 'lib/rbsso/authentication.rb', line 30

def to_s
  content.join '|'
end