Last active
December 14, 2015 01:58
-
-
Save clarkbw/5009732 to your computer and use it in GitHub Desktop.
Adds persona support to the discourse platform using the omniauth-persona gem ( https://github.com/pklingem/omniauth-persona )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Gemfile b/Gemfile | |
index 6966c65..59e7dc3 100644 | |
--- a/Gemfile | |
+++ b/Gemfile | |
@@ -34,6 +34,7 @@ gem "omniauth-openid" | |
gem "openid-redis-store" | |
gem "omniauth-facebook" | |
gem "omniauth-twitter" | |
+gem "omniauth-persona" | |
gem 'oj' | |
gem 'pbkdf2' | |
gem 'pg' | |
diff --git a/Gemfile.lock b/Gemfile.lock | |
index 96d5cc4..22b96c6 100644 | |
--- a/Gemfile.lock | |
+++ b/Gemfile.lock | |
@@ -287,6 +287,10 @@ GEM | |
omniauth-openid (1.0.1) | |
omniauth (~> 1.0) | |
rack-openid (~> 1.3.1) | |
+ omniauth-persona (0.0.1) | |
+ faraday | |
+ multi_json | |
+ omniauth (~> 1.0) | |
omniauth-twitter (0.0.14) | |
multi_json (~> 1.3) | |
omniauth-oauth (~> 1.0) | |
@@ -488,6 +492,7 @@ DEPENDENCIES | |
omniauth | |
omniauth-facebook | |
omniauth-openid | |
+ omniauth-persona | |
omniauth-twitter | |
openid-redis-store | |
pbkdf2 | |
diff --git a/app/assets/javascripts/discourse/templates/modal/login.js.handlebars b/app/assets/javascripts/discourse/templates/modal/login.js.handlebars | |
index b605373..bf93e89 100644 | |
--- a/app/assets/javascripts/discourse/templates/modal/login.js.handlebars | |
+++ b/app/assets/javascripts/discourse/templates/modal/login.js.handlebars | |
@@ -5,6 +5,7 @@ | |
<br> | |
<button class="btn btn-social twitter" title="{{i18n login.twitter.title}}" {{action "twitterLogin" target="view"}}>{{i18n login.twitter.title}}</button> | |
<button class="btn btn-social yahoo" title="{{i18n login.yahoo.title}}" {{action openidLogin "yahoo" target="view"}}>{{i18n login.yahoo.title}}</button> | |
+ <button class="btn btn-social persona" title="{{i18n login.persona.title}}" {{action "personaLogin" target="view"}}>{{i18n login.persona.title}}</button> | |
</div> | |
<h3 style="text-align:center; margin-bottom:10px;"> | |
{{i18n login.or}} | |
diff --git a/app/assets/javascripts/discourse/views/modal/login_view.js b/app/assets/javascripts/discourse/views/modal/login_view.js | |
index 73383db..2cad633 100644 | |
--- a/app/assets/javascripts/discourse/views/modal/login_view.js | |
+++ b/app/assets/javascripts/discourse/views/modal/login_view.js | |
@@ -79,6 +79,14 @@ | |
return window.open("/auth/facebook", "_blank", "menubar=no,status=no,height=400,width=800,left=" + left + ",top=" + top); | |
}, | |
+ personaLogin: function() { | |
+ var left, top; | |
+ this.set('authenticate', 'persona'); | |
+ left = this.get('lastX') - 400; | |
+ top = this.get('lastY') - 200; | |
+ return window.open("/auth/persona", "_blank", "menubar=no,status=no,height=300,width=400,left=" + left + ",top=" + top); | |
+ }, | |
+ | |
openidLogin: function(provider) { | |
var left, top; | |
left = this.get('lastX') - 400; | |
diff --git a/app/assets/stylesheets/components/buttons.css.scss b/app/assets/stylesheets/components/buttons.css.scss | |
index 80e8756..0d54219 100755 | |
--- a/app/assets/stylesheets/components/buttons.css.scss | |
+++ b/app/assets/stylesheets/components/buttons.css.scss | |
@@ -162,6 +162,12 @@ | |
content: "Y"; | |
} | |
} | |
+ &.persona { | |
+ background: $persona; | |
+ &:before { | |
+ content: "P"; | |
+ } | |
+ } | |
} | |
// Button Sizes | |
diff --git a/app/assets/stylesheets/foundation/variables.scss b/app/assets/stylesheets/foundation/variables.scss | |
index 39eea57..e773569 100644 | |
--- a/app/assets/stylesheets/foundation/variables.scss | |
+++ b/app/assets/stylesheets/foundation/variables.scss | |
@@ -123,6 +123,7 @@ $google: #5b76f7 !default; | |
$facebook: #3b5998 !default; | |
$twitter: #00bced !default; | |
$yahoo: #810293 !default; | |
+$persona: #297dc3 !default; | |
// Layout dimensions | |
diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb | |
index a719a14..2e96a50 100644 | |
--- a/app/controllers/users/omniauth_callbacks_controller.rb | |
+++ b/app/controllers/users/omniauth_callbacks_controller.rb | |
@@ -19,6 +19,8 @@ class Users::OmniauthCallbacksController < ApplicationController | |
create_or_sign_on_user_using_twitter(auth_token) | |
when "google", "yahoo" | |
create_or_sign_on_user_using_openid(auth_token) | |
+ when "persona" | |
+ create_or_sign_on_user_using_persona(auth_token) | |
end | |
end | |
@@ -169,4 +171,42 @@ class Users::OmniauthCallbacksController < ApplicationController | |
end | |
end | |
+ def create_or_sign_on_user_using_persona(auth_token) | |
+ | |
+ data = auth_token[:info] | |
+ | |
+ email = data[:email] | |
+ expires = auth_token[:expires] # we don't save this but it should probably be used | |
+ | |
+ # If the auth supplies a name / username, use those. Otherwise start with email. | |
+ name = data[:name] || email | |
+ username = email | |
+ | |
+ user = User.find_by_email(email) | |
+ | |
+ if user | |
+ | |
+ # If we have to approve users | |
+ if SiteSetting.must_approve_users? and !user.approved? | |
+ @data = {awaiting_approval: true} | |
+ else | |
+ log_on_user(user) | |
+ @data = {authenticated: true} | |
+ end | |
+ | |
+ else | |
+ @data = { | |
+ email: email, | |
+ name: User.suggest_name(name), | |
+ username: User.suggest_username(username), | |
+ email_valid: true , | |
+ auth_provider: data[:provider] || params[:provider] | |
+ } | |
+ session[:authentication] = { | |
+ email: @data[:email], | |
+ email_valid: @data[:email_valid] | |
+ } | |
+ end | |
+ end | |
+ | |
end | |
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb | |
index 41e4c8d..57bb35b 100644 | |
--- a/config/initializers/omniauth.rb | |
+++ b/config/initializers/omniauth.rb | |
@@ -27,4 +27,5 @@ Rails.application.config.middleware.use OmniAuth::Builder do | |
SiteSetting.twitter_consumer_key, | |
SiteSetting.twitter_consumer_secret | |
+ provider :persona | |
end | |
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml | |
index 811a7b6..50a3b13 100644 | |
--- a/config/locales/client.en.yml | |
+++ b/config/locales/client.en.yml | |
@@ -245,6 +245,9 @@ en: | |
yahoo: | |
title: "Log In with Yahoo" | |
message: "Authenticating with Yahoo (make sure pop up blockers are not enabled)" | |
+ persona: | |
+ title: "Log In with Persona" | |
+ message: "Authenticating with Persona (make sure pop up blockers are not enabled)" | |
composer: | |
saving_draft_tip: "saving" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment