Class: Sinatra::Authorization::ProtectedAction

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatras-hat/auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, credentials = {}, &block) ⇒ ProtectedAction

Returns a new instance of ProtectedAction.



8
9
10
# File 'lib/sinatras-hat/auth.rb', line 8

def initialize(context, credentials={}, &block)
  @credentials, @context, @block = credentials, context, block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/sinatras-hat/auth.rb', line 6

def block
  @block
end

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/sinatras-hat/auth.rb', line 6

def context
  @context
end

#credentialsObject (readonly)

Returns the value of attribute credentials.



6
7
8
# File 'lib/sinatras-hat/auth.rb', line 6

def credentials
  @credentials
end

Instance Method Details

#check!Object



12
13
14
15
16
# File 'lib/sinatras-hat/auth.rb', line 12

def check!
  unauthorized! unless auth.provided?
  bad_request! unless auth.basic?
  unauthorized! unless authorize(*auth.credentials)
end

#remote_userObject



18
19
20
# File 'lib/sinatras-hat/auth.rb', line 18

def remote_user
  auth.username
end