Reputation: 25102
What is the right way to set WWW-Authenticate header in rails response?
Currently I do it this way:
headers["WWW-Authenticate"] = %(Basic realm="My Realm")
render :json => {:message =>I18n.t("errors.messages.authorization_error")}, :status => :unauthorized
I think that there is a more simple way to set this header using rails api. Without accessing header dictionary directly.
Upvotes: 5
Views: 1797
Reputation: 12643
There is nothing wrong with what you are doing, but rails does have HTTP authenication baked in. Please see this link: http://apidock.com/rails/ActionController/HttpAuthentication/Basic/ControllerMethods/authenticate_or_request_with_http_basic
Upvotes: 2