From 369bb78f8e49c4cc4c3b585b40e4dc143a8b2669 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 6 Jun 2017 15:02:11 -0400 Subject: [PATCH] FIX: Support for cookies in onebox redirects --- Gemfile | 2 +- Gemfile.lock | 4 ++-- lib/oneboxer.rb | 12 ++++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index a3222a8b26c..5bf31ec3329 100644 --- a/Gemfile +++ b/Gemfile @@ -48,7 +48,7 @@ gem 'onebox' gem 'http_accept_language', '~>2.0.5', require: false gem 'ember-rails', '0.18.5' -gem 'ember-source', '2.10.0' +gem 'ember-source' gem 'ember-handlebars-template', '0.7.5' gem 'barber' gem 'babel-transpiler' diff --git a/Gemfile.lock b/Gemfile.lock index c6d082c55bb..4be4a6019db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -214,7 +214,7 @@ GEM omniauth-twitter (1.3.0) omniauth-oauth (~> 1.1) rack - onebox (1.8.10) + onebox (1.8.11) fast_blank (>= 1.0.0) htmlentities (~> 4.3) moneta (~> 1.0) @@ -409,7 +409,7 @@ DEPENDENCIES email_reply_trimmer (= 0.1.6) ember-handlebars-template (= 0.7.5) ember-rails (= 0.18.5) - ember-source (= 2.10.0) + ember-source excon execjs fabrication (= 2.9.8) diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb index d90475c36b7..eb495311892 100644 --- a/lib/oneboxer.rb +++ b/lib/oneboxer.rb @@ -144,9 +144,17 @@ module Oneboxer def self.onebox_raw(url) Rails.cache.fetch(onebox_cache_key(url), expires_in: 1.day) do - uri = FinalDestination.new(url).resolve + fd = FinalDestination.new(url) + uri = fd.resolve return blank_onebox if uri.blank? || SiteSetting.onebox_domains_blacklist.include?(uri.hostname) - options = { cache: {}, max_width: 695, sanitize_config: Sanitize::Config::DISCOURSE_ONEBOX } + options = { + cache: {}, + max_width: 695, + sanitize_config: Sanitize::Config::DISCOURSE_ONEBOX + } + + options[:cookie] = fd.cookie if fd.cookie + r = Onebox.preview(url, options) { onebox: r.to_s, preview: r.try(:placeholder_html).to_s } end