Module: WSOC::Helpers::Authentication

Included in:
WSOC::Helpers
Defined in:
lib/wsoc/helpers/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authorized?Boolean

Checks to see if the requesting user is authorized.

Returns:

  • (Boolean)

    Specifies whether or not the client is authenticated.

Since:

  • 0.1.1



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wsoc/helpers/authentication.rb', line 51

def authorized?
  @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.

Yields:

  • [] If a block is given, it will be called if the client is authenticated.

Since:

  • 0.1.1



34
35
36
37
38
39
40
41
# File 'lib/wsoc/helpers/authentication.rb', line 34

def protected!(&block)
  if authorized?
    block.call() if block
  else
    response['WWW-Authenticate'] = %(Basic realm="HTTP Auth Test")
    throw :halt, [401, "Not authorized\n"]
  end
end