lib/micropub/server/rails/middleware.rb in micropub-server-rails-0.1.4 vs lib/micropub/server/rails/middleware.rb in micropub-server-rails-0.1.5

- old
+ new

@@ -1,43 +1,36 @@ require 'micropub' -Micropub.configure do |c| - c.token_endpoint = "https://tokens.indieauth.com/token" - c.me = "http://bookisworthy.com" - c.allowed_scopes = [:post] -end - module Micropub::Server::Rails class Middleware def initialize(app) @app = app end def call(env) if env["PATH_INFO"] == "/micropub" token = Micropub::Token.new(auth_token(env)) - puts token.inspect - if token.valid? - response - else - error_response - end + token.valid? ? response : error_response else @app.call env end end def auth_token(env) - input = env["HTTP_AUTHORIZATION"] || request(env).params[:access_token] || "" + input = env["HTTP_AUTHORIZATION"] || request(env).params["access_token"] || "" input.split("Bearer ").last end def response - [201, headers, ["I am micropub."]] + [201, headers, body] end def error_response - [401, {}, [""]] + [401, {}, body] + end + + def body + [""] end def request(env) Rack::Request.new(env) end