Sha256: 77fb18e3ff2696e016d6d517bad9e500d05d088ef2ff2c6330cea79d3c9df48c

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'facemock'

module Facemock
  module OAuth
    class Authentication < RackMiddleware
      DEFAULT_PATH = "/facemock/oauth"
      @path = DEFAULT_PATH

      def call(env)
        if env["PATH_INFO"] == Authentication.path && env["REQUEST_METHOD"] == "POST"
          raw_body = env['rack.input'].gets
          body     = query_string_to_hash(raw_body)
          email    = body["email"]
          password = body["pass"]

          user = Facemock::Database::User.find_by_email(email)
          if user && user.password == password
            code = Facemock::Database::AuthorizationCode.create!(user_id: user.id)
            location = location(env, CallbackHook.path, { code: code.string })
          else
            location = location(env, "/facemock/sign_in")
          end

          code   = 302
          body   = []
          header = { "Content-Type"           => "text/html;charset=utf-8",
                     "Location"               => location,
                     "Content-Length"         => content_length(body).to_s,
                     "X-XSS-Protection"       => "1; mode=block",
                     "X-Content-Type-Options" => "nosniff",
                     "X-Frame-Options"        => "SAMEORIGIN" }
          [ code, header, body ]
        else
          super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facemock-oauth-0.0.1 lib/facemock/oauth/authentication.rb