Skip to content

Commit

Permalink
[B] Address OAuth regression
Browse files Browse the repository at this point in the history
When we installed Draper to provide decorators to our mailers, we
inadvertently broke the OAuth controller. This is likely due to the
following issues in Draper, which do not appear to have been fully
solved in Draper 3.0.1.

Because this is the only place we use ActionView outside of Mailers,
for now we will just render the content from the controller. In the
future, if we need more view functionality, we'll use cells.

See:
rails/rails#27211
drapergem/draper#793

Fixes #1631
  • Loading branch information
zdavis authored and SMaxOwok committed Dec 13, 2018
1 parent 11be132 commit 17608a7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
24 changes: 22 additions & 2 deletions api/app/controllers/oauth_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class OauthController < ApplicationController
include ActionView::Rendering

skip_after_action :set_content_type

Expand All @@ -11,11 +10,32 @@ def authorize

@oauth_payload = ExternalAuth::Payload.new outcome

render layout: false
# rubocop:disable Rails/OutputSafety
render html: body.html_safe, layout: false
# rubocop:enable Rails/OutputSafety
end

private

def body
<<~HEREDOC
<!DOCTYPE html>
<html>
<head>
<title>Authentication successful!</title>
<style></style>
</head>
<body>
<h1>Authorization success!</h1>
<script type="text/javascript">
window.opener.postMessage(#{@oauth_payload.to_json}, "*");
window.close();
</script>
</body>
</html>
HEREDOC
end

def omniauth_hash
request.env["omniauth.auth"]
end
Expand Down
14 changes: 0 additions & 14 deletions api/app/views/oauth/authorize.html.erb

This file was deleted.

21 changes: 21 additions & 0 deletions api/spec/requests/oauth_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "rails_helper"

RSpec.describe "Oauth", type: :request do
describe "responds with a list of projects" do
before(:each) { get "/auth/google_oauth2/callback" }
describe "the response" do

it "has a non-blank body" do
expect(response.body.blank?).to be false
end

it "has a 200 status code" do
get api_v1_collections_path
expect(response).to have_http_status(200)
end


end
end

end

0 comments on commit 17608a7

Please sign in to comment.