Class: RoadForest::Authorization::AuthenticationChain

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/authorization.rb

Defined Under Namespace

Classes: Basic, Scheme

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ AuthenticationChain

Returns a new instance of AuthenticationChain.



130
131
132
# File 'lib/roadforest/authorization.rb', line 130

def initialize(store)
  @store = store
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



133
134
135
# File 'lib/roadforest/authorization.rb', line 133

def store
  @store
end

Instance Method Details

#add_account(user, password, token) ⇒ Object



147
148
149
# File 'lib/roadforest/authorization.rb', line 147

def (user,password,token)
  @store.(user,password,token)
end

#authenticate(header) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/roadforest/authorization.rb', line 151

def authenticate(header)
  return nil if header.nil?
  scheme, credentials = header.split(/\s+/, 2)

  handler = handler_for(scheme)
  return nil if handler.nil?

  entity = handler.authenticated_entity(credentials, store)
  return nil if entity.nil?
  return nil unless entity.authenticated?
  return entity
end

#challenge(options) ⇒ Object



141
142
143
144
145
# File 'lib/roadforest/authorization.rb', line 141

def challenge(options)
  (Scheme.registry.names.map do |scheme_name|
    handler_for(scheme_name).challenge(options)
  end).join(", ")
end

#handler_for(scheme) ⇒ Object



135
136
137
138
139
# File 'lib/roadforest/authorization.rb', line 135

def handler_for(scheme)
  Scheme.get(scheme)
rescue
  nil
end