Class: Round::Client::Context

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

Defined Under Namespace

Modules: Scheme

Constant Summary collapse

SCHEMES =
[Scheme::DEVICE, Scheme::APPLICATION, Scheme::IDENTIFY]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



81
82
83
# File 'lib/round/client.rb', line 81

def initialize
  @schemes = {}
end

Instance Attribute Details

#mfa_tokenObject

Returns the value of attribute mfa_token.



79
80
81
# File 'lib/round/client.rb', line 79

def mfa_token
  @mfa_token
end

#schemesObject

Returns the value of attribute schemes.



79
80
81
# File 'lib/round/client.rb', line 79

def schemes
  @schemes
end

Instance Method Details

#authorize(scheme, params) ⇒ Object

Is there a list of accepted params somewhere?

Raises:

  • (ArgumentError)


86
87
88
89
90
# File 'lib/round/client.rb', line 86

def authorize(scheme, params)
  raise ArgumentError, 'Params cannot be empty.' if params.empty?
  raise ArgumentError, 'Unknown auth scheme' unless SCHEMES.include?(scheme)
  @schemes[scheme] = params
end

#authorizer(schemes: [], action: 'NULL ACTION', **kwargs) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/round/client.rb', line 100

def authorizer(schemes: [], action: 'NULL ACTION', **kwargs)
  schemes.each do |scheme|
    if (params = @schemes[scheme])
      credential = compile_params(params)
      return [scheme, credential]
    end
  end
  raise "Action: #{action}.  No authorization available for '#{schemes}'"
end

#compile_params(params) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/round/client.rb', line 92

def compile_params(params)
  compiled = params.map do |key, value|
    %Q(#{key}="#{value}")
  end.join(', ')
  compiled << ", mfa_token=#{@mfa_token}" if @mfa_token
  compiled
end

#inspectObject



110
111
112
113
114
# File 'lib/round/client.rb', line 110

def inspect
  # Hide the secret token when printed
  id = "%x" % (self.object_id << 1)
  %Q(#<#{self.class}:0x#{id})
end