Sha256: 4fd084bb9284bd7b531675236b96bab5016c3c808c354a38992de2c7c8387fe5

Contents?: true

Size: 1.54 KB

Versions: 20

Compression:

Stored size: 1.54 KB

Contents

module ShopifyCLI
  class IdentityAuth
    class Servlet < WEBrick::HTTPServlet::AbstractServlet
      ERB_FILENAME = File.join(ROOT, "lib/shopify_cli/assets/post_auth_page/index.html.erb")
      CSS_FILENAME = File.join(ROOT, "lib/shopify_cli/assets/post_auth_page/style.css")

      def initialize(server, identity_auth, token)
        super
        @server = server
        @identity_auth = identity_auth
        @state_token = token
      end

      def do_GET(req, res) # rubocop:disable Naming/MethodName
        if !req.query["error"].nil?
          respond_with(
            res,
            400,
            Context.message("core.identity_auth.servlet.invalid_request_response", req.query["error_description"])
          )
        elsif req.query["state"] != @state_token
          response_message = Context.message("core.identity_auth.servlet.invalid_state_response")
          req.query.merge!("error" => "invalid_state", "error_description" => response_message)
          respond_with(res, 403, response_message)
        else
          respond_with(res, 200, Context.message("core.identity_auth.servlet.success_response"))
        end
        @identity_auth.response_query = req.query
        @server.shutdown
      end

      def respond_with(response, status, message)
        successful = status == 200
        locals = {
          status: status,
          message: message,
          css: File.read(CSS_FILENAME),
        }
        response.status = status
        response.body = ERB.new(File.read(ERB_FILENAME)).result(binding)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shopify-cli-2.36.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.35.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.34.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.33.1 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.33.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.32.1 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.32.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.31.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.30.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.29.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.28.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.27.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.26.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.25.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.24.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.23.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.22.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.21.0 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.20.1 lib/shopify_cli/identity_auth/servlet.rb
shopify-cli-2.20.0 lib/shopify_cli/identity_auth/servlet.rb