]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api_controller.rb
Simplify deny_access handling
[rails.git] / app / controllers / api_controller.rb
1 class ApiController < ApplicationController
2   skip_before_action :verify_authenticity_token
3
4   def deny_access(_exception)
5     if current_token
6       set_locale
7       report_error t("oauth.permissions.missing"), :forbidden
8     elsif current_user
9       head :forbidden
10     else
11       realm = "Web Password"
12       errormessage = "Couldn't authenticate you"
13       response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
14       render :plain => errormessage, :status => :unauthorized
15     end
16   end
17 end