lib/satz.rb in satz-0.0.3 vs lib/satz.rb in satz-0.0.4

- old
+ new

@@ -20,11 +20,11 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. require "syro" require "json" -require "base64" +require "basica" class Satz # The JSON module from stdlib provides a safe way of loading data # with the `parse` method, but the most widespread API for encoding @@ -54,11 +54,11 @@ def self.serializer=(value) @@serializer = value end class Deck < Syro::Deck - HTTP_AUTHORIZATION = "HTTP_AUTHORIZATION".freeze + include Basica # Checks the Basic Auth headers and yields # user and pass if credentials are provided. # Returns nil if there are no credentials or # if the block returns false or nil. @@ -73,17 +73,10 @@ # res.status = 401 # reply(error: "Unauthorized") # end # def auth - http_auth = env.fetch(HTTP_AUTHORIZATION) do - return nil - end - - cred = http_auth.split(" ")[1] - user, pass = Base64.decode64(cred).split(":") - - yield(user, pass) || nil + basic_auth(env) { |user, pass| yield(user, pass) } end # Respond by default with JSON. The default charset # for "application/json" is UTF-8. def default_headers