Commit 7c0e23cb0fbef49c0c4960ddf2029bc48d105530

Authored by Weblate
2 parents 7fad273e 7bdb0c8b

Merge remote-tracking branch 'origin/master'

plugins/oauth_client/Gemfile
1 gem 'omniauth', '~> 1.2.2' 1 gem 'omniauth', '~> 1.2.2'
2 gem 'omniauth-facebook', '~> 2.0.0' 2 gem 'omniauth-facebook', '~> 2.0.0'
  3 +gem 'omniauth-twitter', '~> 1.0.1'
3 gem "omniauth-google-oauth2", '~> 0.2.6' 4 gem "omniauth-google-oauth2", '~> 0.2.6'
4 gem "omniauth-oauth2", '~> 1.3.1' 5 gem "omniauth-oauth2", '~> 1.3.1'
  6 +gem "omniauth-github", '~> 1.1.2'
plugins/oauth_client/README.md
@@ -33,6 +33,20 @@ Facebook @@ -33,6 +33,20 @@ Facebook
33 33
34 [Create Facebook application](https://developers.facebook.com/docs/facebook-login/v2.1) 34 [Create Facebook application](https://developers.facebook.com/docs/facebook-login/v2.1)
35 35
  36 +Github
  37 +--------
  38 +
  39 +[Create Github application](https://github.com/settings/developers)
  40 +
  41 +Twitter
  42 +--------
  43 +
  44 +- Specially on twitter you need to request user's email address, see more
  45 +in https://dev.twitter.com/rest/reference/get/account/verify_credentials
  46 +
  47 +[Create Twitter application](https://apps.twitter.com/)
  48 +
  49 +
36 Callback 50 Callback
37 ======== 51 ========
38 52
plugins/oauth_client/features/create_provider.feature 0 → 100644
@@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
  1 +Feature: Create Twitter provider
  2 + As a environment admin
  3 + I want to be able to create a new twitter provider
  4 + So that users can login wth different strategies
  5 +
  6 +Background:
  7 + Given "OauthProvider" plugin is enabled
  8 + And I am logged in as admin
  9 + And I go to /admin/plugins
  10 + And I check "Oauth Client Plugin"
  11 + And I press "Save changes"
  12 +
  13 +Scenario: Create a twitter provider
  14 + Given I go to /admin/plugin/oauth_client/new
  15 + And I fill in "oauth_client_plugin_provider_name" with "myid"
  16 + And I fill in "oauth_client_plugin_provider[name]" with "google"
  17 + And I fill in "oauth_client_plugin_provider_client_secret" with "mysecret"
  18 + And I check "oauth_client_plugin_provider[enabled]"
  19 + And I select "twitter" from "oauth_client_plugin_provider_strategy"
  20 + Then I should see "To use this provider you need to request the user email in your app"
plugins/oauth_client/lib/oauth_client_plugin.rb
@@ -31,13 +31,20 @@ class OauthClientPlugin < Noosfero::Plugin @@ -31,13 +31,20 @@ class OauthClientPlugin < Noosfero::Plugin
31 31
32 PROVIDERS = { 32 PROVIDERS = {
33 :facebook => { 33 :facebook => {
34 - :name => 'Facebook' 34 + :name => 'Facebook',
  35 + :info_fields => 'name,email'
35 }, 36 },
36 :google_oauth2 => { 37 :google_oauth2 => {
37 :name => 'Google' 38 :name => 'Google'
38 }, 39 },
39 :noosfero_oauth2 => { 40 :noosfero_oauth2 => {
40 :name => 'Noosfero' 41 :name => 'Noosfero'
  42 + },
  43 + :github => {
  44 + :name => 'Github'
  45 + },
  46 + :twitter => {
  47 + :name => 'Twitter'
41 } 48 }
42 } 49 }
43 50
@@ -62,8 +69,9 @@ class OauthClientPlugin < Noosfero::Plugin @@ -62,8 +69,9 @@ class OauthClientPlugin < Noosfero::Plugin
62 provider_id = request.params['id'] 69 provider_id = request.params['id']
63 provider_id ||= request.session['omniauth.params']['id'] if request.session['omniauth.params'] 70 provider_id ||= request.session['omniauth.params']['id'] if request.session['omniauth.params']
64 provider = environment.oauth_providers.find(provider_id) 71 provider = environment.oauth_providers.find(provider_id)
  72 + strategy.options.merge! consumer_key: provider.client_id, consumer_secret: provider.client_secret
65 strategy.options.merge! client_id: provider.client_id, client_secret: provider.client_secret 73 strategy.options.merge! client_id: provider.client_id, client_secret: provider.client_secret
66 - strategy.options.merge! provider.options.symbolize_keys 74 + strategy.options.merge! options
67 75
68 request.session[:provider_id] = provider_id 76 request.session[:provider_id] = provider_id
69 } 77 }
@@ -95,4 +103,8 @@ class OauthClientPlugin < Noosfero::Plugin @@ -95,4 +103,8 @@ class OauthClientPlugin < Noosfero::Plugin
95 } 103 }
96 end 104 end
97 105
  106 + def js_files
  107 + ["script.js"]
  108 + end
  109 +
98 end 110 end
plugins/oauth_client/public/script.js 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +$(document).ready(function(){
  2 + select_box_event();
  3 +});
  4 +
  5 +var toggle_info_message = function(){
  6 + var selected_option = $("#oauth_client_plugin_provider_strategy option:selected");
  7 + if (selected_option.length){
  8 + if (selected_option.val() === "twitter"){
  9 + $(".remember-enable-email").removeClass("hidden");
  10 + } else {
  11 + $(".remember-enable-email").addClass("hidden");
  12 + }
  13 + }
  14 +};
  15 +
  16 +var select_box_event = function(){
  17 + var select_box = $("#oauth_client_plugin_provider_strategy");
  18 + select_box.on("change",function(){
  19 + toggle_info_message();
  20 + });
  21 +};
plugins/oauth_client/public/style.css
@@ -16,3 +16,7 @@ @@ -16,3 +16,7 @@
16 .oauth-login .provider .developer { 16 .oauth-login .provider .developer {
17 display: none; 17 display: none;
18 } 18 }
  19 +
  20 +.remember-enable-email.hidden {
  21 + display: none;
  22 +}
plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb
@@ -15,6 +15,10 @@ @@ -15,6 +15,10 @@
15 <%= labelled_form_field _('Strategy'), f.select(:strategy, OauthClientPlugin::PROVIDERS) %> 15 <%= labelled_form_field _('Strategy'), f.select(:strategy, OauthClientPlugin::PROVIDERS) %>
16 </div> 16 </div>
17 17
  18 + <div class="remember-enable-email hidden">
  19 + <span class="error"><%=_('To use this provider you need to request the user email in your app')%></span>
  20 + </div>
  21 +
18 <div class="client-id"> 22 <div class="client-id">
19 <%= labelled_form_field _('Client Id'), f.text_field(:client_id) %> 23 <%= labelled_form_field _('Client Id'), f.text_field(:client_id) %>
20 </div> 24 </div>