Module: WSOC::Helpers::Authentication
- Included in:
- WSOC::Helpers
- Defined in:
- lib/wsoc/helpers/authentication.rb
Instance Method Summary collapse
-
#authorized? ⇒ Boolean
Checks to see if the requesting user is authorized.
-
#protected! { ... } ⇒ Object
Protects an action by requiring HTTP Basic Access Authentication.
Instance Method Details
#authorized? ⇒ Boolean
Checks to see if the requesting user is authorized.
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wsoc/helpers/authentication.rb', line 51 def @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? && \ @auth.basic? && \ @auth.credentials && \ @auth.credentials == [ WSOC::Config::COURSE_AUTH_USER, WSOC::Config::COURSE_AUTH_PASSWORD ] end |
#protected! { ... } ⇒ Object
Protects an action by requiring HTTP Basic Access Authentication.
34 35 36 37 38 39 40 41 |
# File 'lib/wsoc/helpers/authentication.rb', line 34 def protected!(&block) if block.call() if block else response['WWW-Authenticate'] = %(Basic realm="HTTP Auth Test") throw :halt, [401, "Not authorized\n"] end end |