Module: Integrity::Helpers::Authorization

Includes:
Sinatra::Authorization
Included in:
Integrity::Helpers
Defined in:
lib/integrity/helpers/authorization.rb

Instance Method Summary collapse

Instance Method Details

#authorization_realmObject



8
9
10
# File 'lib/integrity/helpers/authorization.rb', line 8

def authorization_realm
  "Integrity"
end

#authorize(user, password) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/integrity/helpers/authorization.rb', line 17

def authorize(user, password)
  if Integrity.config[:hash_admin_password]
    password = Digest::SHA1.hexdigest(password)
  end

  !Integrity.config[:use_basic_auth] ||
  (Integrity.config[:admin_username] == user &&
    Integrity.config[:admin_password] == password)
end

#authorized?Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/integrity/helpers/authorization.rb', line 12

def authorized?
  return true unless Integrity.config[:use_basic_auth]
  !!request.env["REMOTE_USER"]
end

#unauthorized!(realm = authorization_realm) ⇒ Object



27
28
29
30
# File 'lib/integrity/helpers/authorization.rb', line 27

def unauthorized!(realm=authorization_realm)
  response["WWW-Authenticate"] = %(Basic realm="#{realm}")
  throw :halt, [401, show(:unauthorized, :title => "incorrect credentials")]
end