Class: RbSSO::Client

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

Defined Under Namespace

Classes: NonceMismatch, TicketExpired, WrongService

Instance Method Summary collapse

Constructor Details

#initialize(service, key) ⇒ Client

Returns a new instance of Client.



25
26
27
28
29
30
31
32
# File 'lib/rbsso/client.rb', line 25

def initialize(service, key)
  if !key || key !~ /[0-9a-f]{64}/i
    raise ArgumentError, "key MUST be 32 bytes, hex encoded string, was: #{key}"
  end
  @service = service
  key = RbNaCl::VerifyKey.new [key].pack('H*')
  @verify_key = key
end

Instance Method Details

#open(ticket_string, nonce: nil) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
# File 'lib/rbsso/client.rb', line 34

def open(ticket_string, nonce: nil)
  ticket = RbSSO::Ticket.open ticket_string, verify_key
  auth = RbSSO::Authentication.parse ticket.content
  raise TicketExpired.new(auth.expires) if auth.expired?
  raise WrongService.new(service, auth.service) if auth.service != service
  raise NonceMismatch.new(nonce, auth.nonce) if auth.nonce != nonce
  auth.to_info
end