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) @env = env if env["PATH_INFO"] == "/micropub" token = Micropub::Token.new(auth_token) if token.valid? response else error_response end else @app.call env end end def env @env end def auth_token @auth_token ||= begin input = env["HTTP_AUTHORIZATION"] || params[:access_token] || "" input.split("Bearer ").last end end def response [201, headers, ["I am micropub."]] end def error_response [401, {}, [""]] end def request @request ||= Rack::Request.new(env) end def params request.params end def headers { "Location" => "http://bookisworthy.com/posts/1", "Content-Type" => "text/plain; charset=utf-8" } end end end