Method: Visor::Common::Util#authorize
- Defined in:
- lib/common/util.rb
#authorize(env, vas) ⇒ String
Authenticate an user request by analysing the request authorization string.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/common/util.rb', line 147 def (env, vas) auth = env['headers']['Authorization'] raise Visor::Common::Exception::Forbidden, "Authorization not provided." unless auth access_key = auth.scan(/\ (\w+):/).flatten.first raise Visor::Common::Exception::Forbidden, "No access key found in Authorization." unless access_key begin user = vas.get_user(access_key) rescue Visor::Common::Exception::InternalError => e raise Visor::Common::Exception::InternalError, e. rescue => e nil end raise Visor::Common::Exception::Forbidden, "No user found with access key '#{access_key}'." unless user sign = sign_request(user[:access_key], user[:secret_key], env['REQUEST_METHOD'], env['REQUEST_PATH'], env['headers']) raise Visor::Common::Exception::Forbidden, "Invalid authorization, signatures do not match." unless auth == sign access_key end |