From b3aebca406ba208f9e59e8488dbc618f3c9f8949 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 13 Oct 2015 12:23:34 +1100 Subject: [PATCH] FEATURE: allow auto provider to specify "full screen login" this feature means we attempt to log in without opening a frame. --- .../discourse/controllers/login.js.es6 | 33 +++++++++++-------- .../users/omniauth_callbacks_controller.rb | 12 +++++++ .../omniauth_callbacks/complete.html.erb | 2 +- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index 3297e1c0517..8d52622104c 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -113,21 +113,26 @@ export default Ember.Controller.extend(ModalFunctionality, { if(customLogin){ customLogin(); } else { - this.set('authenticate', name); - const left = this.get('lastX') - 400; - const top = this.get('lastY') - 200; + var authUrl = Discourse.getURL("/auth/" + name); + if (loginMethod.get("full_screen_login")) { + window.location = authUrl; + } else { + this.set('authenticate', name); + const left = this.get('lastX') - 400; + const top = this.get('lastY') - 200; - const height = loginMethod.get("frameHeight") || 400; - const width = loginMethod.get("frameWidth") || 800; - const w = window.open(Discourse.getURL("/auth/" + name), "_blank", - "menubar=no,status=no,height=" + height + ",width=" + width + ",left=" + left + ",top=" + top); - const self = this; - const timer = setInterval(function() { - if(!w || w.closed) { - clearInterval(timer); - self.set('authenticate', null); - } - }, 1000); + const height = loginMethod.get("frameHeight") || 400; + const width = loginMethod.get("frameWidth") || 800; + const w = window.open(authUrl, "_blank", + "menubar=no,status=no,height=" + height + ",width=" + width + ",left=" + left + ",top=" + top); + const self = this; + const timer = setInterval(function() { + if(!w || w.closed) { + clearInterval(timer); + self.set('authenticate', null); + } + }, 1000); + } } }, diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index b61ff367806..f8784e9e7af 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -36,6 +36,18 @@ class Users::OmniauthCallbacksController < ApplicationController @auth_result = authenticator.after_authenticate(auth) + origin = request.env['omniauth.origin'] + if origin.present? + parsed = URI.parse(@origin) rescue nil + if parsed + @origin = parsed.path + end + end + + unless @origin.present? + @origin = Discourse.base_uri("/") + end + if @auth_result.failed? flash[:error] = @auth_result.failed_reason.html_safe return render('failure') diff --git a/app/views/users/omniauth_callbacks/complete.html.erb b/app/views/users/omniauth_callbacks/complete.html.erb index 86c1c3f1332..d6c6eeb7b57 100644 --- a/app/views/users/omniauth_callbacks/complete.html.erb +++ b/app/views/users/omniauth_callbacks/complete.html.erb @@ -26,7 +26,7 @@ window.opener.Discourse.authenticationComplete(<%=@auth_result.to_client_hash.to_json.html_safe%>); window.close(); } else { - window.location = '<%= Discourse.base_uri("/") %>'; + window.location = <%= @origin.inspect %>; }