Note that there are some explanatory texts on larger screens.

plurals
  1. POUse HTTP Digest Authentication for a Single Route
    primarykey
    data
    text
    <p>I'd like to use HTTP Digest authentication for a specific route in my modular Sinatra App.</p> <p>The examples listed within the <a href="http://recipes.sinatrarb.com/p/middleware/rack_auth_basic_and_digest" rel="nofollow">sinatra recipes website</a> simply describe how to enable digest auth for an entire app. The solution presented for getting this to work for specific routes is to create two separate apps, (one with digest auth and another without) placing the protected and unprotected routes in their respective applications.</p> <p>That would require something like the following:</p> <pre><code>require 'sinatra/base' class Protected &lt; Sinatra::Base use Rack::Auth::Basic, "Protected Area" do |username, password| username == 'foo' &amp;&amp; password == 'bar' end get '/' do "secret" end end class Public &lt; Sinatra::Base get '/' do "public" end end </code></pre> <p>This seems like overkill to me.</p> <p>Is there a way to protect a single route in a modular sinatra app without having to create an entirely new app?</p> <p>There is an example in the <a href="http://www.sinatrarb.com/faq.html#auth" rel="nofollow">FAQ</a> which references creating an instance of Rack::Auth::Basic::Request and passing in the environment but doing something like this with digest auth would differ greatly and be much more of a manual authentication procedure.</p> <p>Here is the basic authentication example:</p> <pre><code>def authorized? @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? &amp;&amp; @auth.basic? &amp;&amp; @auth.credentials &amp;&amp; @auth.credentials == ['admin', 'admin'] end </code></pre> <p>Does anyone have thoughts on how this could be done?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload