Merge branch 'persona-integration' of git://github.com/callahad/discourse
This commit is contained in:
commit
f7c9efb101
1
Gemfile
1
Gemfile
|
@ -36,6 +36,7 @@ gem "openid-redis-store"
|
||||||
gem "omniauth-facebook"
|
gem "omniauth-facebook"
|
||||||
gem "omniauth-twitter"
|
gem "omniauth-twitter"
|
||||||
gem "omniauth-github"
|
gem "omniauth-github"
|
||||||
|
gem "omniauth-browserid", :git => "git://github.com/callahad/omniauth-browserid.git", :branch => "observer_api"
|
||||||
gem 'oj'
|
gem 'oj'
|
||||||
gem 'pbkdf2'
|
gem 'pbkdf2'
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
|
|
11
Gemfile.lock
11
Gemfile.lock
|
@ -5,6 +5,16 @@ GIT
|
||||||
rack-mini-profiler (0.1.23)
|
rack-mini-profiler (0.1.23)
|
||||||
rack (>= 1.1.3)
|
rack (>= 1.1.3)
|
||||||
|
|
||||||
|
GIT
|
||||||
|
remote: git://github.com/callahad/omniauth-browserid.git
|
||||||
|
revision: af62d667626c1622de6fe13b60849c3640765ab1
|
||||||
|
branch: observer_api
|
||||||
|
specs:
|
||||||
|
omniauth-browserid (0.0.2)
|
||||||
|
faraday
|
||||||
|
multi_json
|
||||||
|
omniauth (~> 1.0)
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
remote: git://github.com/emberjs/ember-rails.git
|
remote: git://github.com/emberjs/ember-rails.git
|
||||||
revision: 57bbe3202725e55a8e4eaccba83d663b26bcf024
|
revision: 57bbe3202725e55a8e4eaccba83d663b26bcf024
|
||||||
|
@ -490,6 +500,7 @@ DEPENDENCIES
|
||||||
nokogiri
|
nokogiri
|
||||||
oj
|
oj
|
||||||
omniauth
|
omniauth
|
||||||
|
omniauth-browserid!
|
||||||
omniauth-facebook
|
omniauth-facebook
|
||||||
omniauth-github
|
omniauth-github
|
||||||
omniauth-openid
|
omniauth-openid
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
{{#if Discourse.SiteSettings.enable_github_logins}}
|
{{#if Discourse.SiteSettings.enable_github_logins}}
|
||||||
<button class="btn btn-social github" title="{{i18n login.github.title}}" {{action "githubLogin" target="view"}}>{{i18n login.github.title}}</button>
|
<button class="btn btn-social github" title="{{i18n login.github.title}}" {{action "githubLogin" target="view"}}>{{i18n login.github.title}}</button>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
{{#if Discourse.SiteSettings.enable_persona_logins}}
|
||||||
|
<br>
|
||||||
|
<button class="btn btn-social persona" title="{{i18n login.persona.title}}" {{action "personaLogin" target="view"}}>{{i18n login.persona.title}}</button>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<h3 style="text-align:center; margin-bottom:10px;">
|
<h3 style="text-align:center; margin-bottom:10px;">
|
||||||
{{i18n login.or}}
|
{{i18n login.or}}
|
||||||
|
|
|
@ -109,6 +109,10 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
|
||||||
return window.open("/auth/github", "_blank", "menubar=no,status=no,height=400,width=800,left=" + left + ",top=" + top);
|
return window.open("/auth/github", "_blank", "menubar=no,status=no,height=400,width=800,left=" + left + ",top=" + top);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
personaLogin: function() {
|
||||||
|
navigator.id.request();
|
||||||
|
},
|
||||||
|
|
||||||
authenticationComplete: function(options) {
|
authenticationComplete: function(options) {
|
||||||
if (options.awaiting_approval) {
|
if (options.awaiting_approval) {
|
||||||
this.flash(Em.String.i18n('login.awaiting_approval'), 'success');
|
this.flash(Em.String.i18n('login.awaiting_approval'), 'success');
|
||||||
|
|
|
@ -168,6 +168,12 @@
|
||||||
content: "g";
|
content: "g";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
&.persona {
|
||||||
|
background: $persona;
|
||||||
|
&:before {
|
||||||
|
content: "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Button Sizes
|
// Button Sizes
|
||||||
|
|
|
@ -124,6 +124,7 @@ $facebook: #3b5998 !default;
|
||||||
$twitter: #00bced !default;
|
$twitter: #00bced !default;
|
||||||
$yahoo: #810293 !default;
|
$yahoo: #810293 !default;
|
||||||
$github: #6d6d6d !default;
|
$github: #6d6d6d !default;
|
||||||
|
$persona: #606060 !default;
|
||||||
|
|
||||||
// Layout dimensions
|
// Layout dimensions
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,13 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
create_or_sign_on_user_using_openid(auth_token)
|
create_or_sign_on_user_using_openid(auth_token)
|
||||||
when "github"
|
when "github"
|
||||||
create_or_sign_on_user_using_github(auth_token)
|
create_or_sign_on_user_using_github(auth_token)
|
||||||
|
when "persona"
|
||||||
|
create_or_sign_on_user_using_persona(auth_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html
|
||||||
|
format.json { render :json => @data }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -169,6 +176,7 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
openid_url: identity_url
|
openid_url: identity_url
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_or_sign_on_user_using_github(auth_token)
|
def create_or_sign_on_user_using_github(auth_token)
|
||||||
|
@ -200,6 +208,37 @@ class Users::OmniauthCallbacksController < ApplicationController
|
||||||
else
|
else
|
||||||
@data[:name] = screen_name
|
@data[:name] = screen_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_or_sign_on_user_using_persona(auth_token)
|
||||||
|
|
||||||
|
email = auth_token[:info][:email]
|
||||||
|
|
||||||
|
user = User.find_by_email(email)
|
||||||
|
|
||||||
|
if user
|
||||||
|
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,
|
||||||
|
email_valid: true,
|
||||||
|
name: User.suggest_name(email),
|
||||||
|
username: User.suggest_username(email),
|
||||||
|
auth_provider: params[:provider].try(:capitalize)
|
||||||
|
}
|
||||||
|
|
||||||
|
session[:authentication] = {
|
||||||
|
email: email,
|
||||||
|
email_valid: true,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -122,6 +122,8 @@ class SiteSetting < ActiveRecord::Base
|
||||||
setting(:github_client_id, '')
|
setting(:github_client_id, '')
|
||||||
setting(:github_client_secret, '')
|
setting(:github_client_secret, '')
|
||||||
|
|
||||||
|
client_setting(:enable_persona_logins, true)
|
||||||
|
|
||||||
setting(:enforce_global_nicknames, true)
|
setting(:enforce_global_nicknames, true)
|
||||||
setting(:discourse_org_access_key, '')
|
setting(:discourse_org_access_key, '')
|
||||||
setting(:enable_s3_uploads, false)
|
setting(:enable_s3_uploads, false)
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<script src="https://login.persona.org/include.js"></script>
|
||||||
|
<script>
|
||||||
|
(function() {
|
||||||
|
var readyCalled = false;
|
||||||
|
navigator.id.watch({
|
||||||
|
onlogin: function(assertion) {
|
||||||
|
if (readyCalled) {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: '/auth/persona/callback',
|
||||||
|
data: { 'assertion': assertion },
|
||||||
|
success: function(data, textStatus, jqXHR) {
|
||||||
|
Discourse.authenticationComplete(data);
|
||||||
|
},
|
||||||
|
dataType: 'json'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onlogout: function() {
|
||||||
|
if (readyCalled) {
|
||||||
|
Discourse.logout();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onready: function() {
|
||||||
|
readyCalled = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
</script>
|
|
@ -60,6 +60,7 @@
|
||||||
<footer id='bottom'></footer>
|
<footer id='bottom'></footer>
|
||||||
|
|
||||||
<%= render :partial => "common/discourse_javascript" %>
|
<%= render :partial => "common/discourse_javascript" %>
|
||||||
|
<%= render :partial => "common/persona_javascript" if SiteSetting.enable_persona_logins %>
|
||||||
<%= render_google_analytics_code %>
|
<%= render_google_analytics_code %>
|
||||||
|
|
||||||
<!-- Discourse Version: <%= Discourse::VERSION::STRING %> -->
|
<!-- Discourse Version: <%= Discourse::VERSION::STRING %> -->
|
||||||
|
|
|
@ -31,4 +31,7 @@ Rails.application.config.middleware.use OmniAuth::Builder do
|
||||||
SiteSetting.github_client_id,
|
SiteSetting.github_client_id,
|
||||||
SiteSetting.github_client_secret
|
SiteSetting.github_client_secret
|
||||||
|
|
||||||
|
provider :browser_id,
|
||||||
|
:name => 'persona'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -251,6 +251,9 @@ en:
|
||||||
github:
|
github:
|
||||||
title: "Log In with Github"
|
title: "Log In with Github"
|
||||||
message: "Authenticating with Github (make sure pop up blockers are not enabled)"
|
message: "Authenticating with Github (make sure pop up blockers are not enabled)"
|
||||||
|
persona:
|
||||||
|
title: "Log In with Any Email Address (Mozilla Persona)"
|
||||||
|
message: "Authenticating with Persona (make sure pop up blockers are not enabled)"
|
||||||
|
|
||||||
composer:
|
composer:
|
||||||
saving_draft_tip: "saving"
|
saving_draft_tip: "saving"
|
||||||
|
|
|
@ -340,6 +340,8 @@ en:
|
||||||
github_client_id: "Client id for Github authentication, registered at https://github.com/settings/applications"
|
github_client_id: "Client id for Github authentication, registered at https://github.com/settings/applications"
|
||||||
github_client_secret: "Client secret for Github authentication, registered at https://github.com/settings/applications"
|
github_client_secret: "Client secret for Github authentication, registered at https://github.com/settings/applications"
|
||||||
|
|
||||||
|
enable_persona_logins: "Enable email-based authentication with Mozilla Persona"
|
||||||
|
|
||||||
allow_import: "Allow import, which can replace ALL site data; leave false unless you plan to do data imports"
|
allow_import: "Allow import, which can replace ALL site data; leave false unless you plan to do data imports"
|
||||||
|
|
||||||
active_user_rate_limit_secs: "How frequently we update the 'last_seen_at' field, in seconds"
|
active_user_rate_limit_secs: "How frequently we update the 'last_seen_at' field, in seconds"
|
||||||
|
|
Loading…
Reference in New Issue