diff --git a/plugins/oauth_client/Gemfile b/plugins/oauth_client/Gemfile index 8c3846a..4bb1cf6 100644 --- a/plugins/oauth_client/Gemfile +++ b/plugins/oauth_client/Gemfile @@ -1,4 +1,6 @@ gem 'omniauth', '~> 1.2.2' gem 'omniauth-facebook', '~> 2.0.0' +gem 'omniauth-twitter', '~> 1.0.1' gem "omniauth-google-oauth2", '~> 0.2.6' gem "omniauth-oauth2", '~> 1.3.1' +gem "omniauth-github", '~> 1.1.2' diff --git a/plugins/oauth_client/README.md b/plugins/oauth_client/README.md index 5528527..45ce7c8 100644 --- a/plugins/oauth_client/README.md +++ b/plugins/oauth_client/README.md @@ -33,6 +33,20 @@ Facebook [Create Facebook application](https://developers.facebook.com/docs/facebook-login/v2.1) +Github +-------- + +[Create Github application](https://github.com/settings/developers) + +Twitter +-------- + +- Specially on twitter you need to request user's email address, see more +in https://dev.twitter.com/rest/reference/get/account/verify_credentials + +[Create Twitter application](https://apps.twitter.com/) + + Callback ======== diff --git a/plugins/oauth_client/features/create_provider.feature b/plugins/oauth_client/features/create_provider.feature new file mode 100644 index 0000000..6605c30 --- /dev/null +++ b/plugins/oauth_client/features/create_provider.feature @@ -0,0 +1,20 @@ +Feature: Create Twitter provider + As a environment admin + I want to be able to create a new twitter provider + So that users can login wth different strategies + +Background: + Given "OauthProvider" plugin is enabled + And I am logged in as admin + And I go to /admin/plugins + And I check "Oauth Client Plugin" + And I press "Save changes" + +Scenario: Create a twitter provider + Given I go to /admin/plugin/oauth_client/new + And I fill in "oauth_client_plugin_provider_name" with "myid" + And I fill in "oauth_client_plugin_provider[name]" with "google" + And I fill in "oauth_client_plugin_provider_client_secret" with "mysecret" + And I check "oauth_client_plugin_provider[enabled]" + And I select "twitter" from "oauth_client_plugin_provider_strategy" + Then I should see "To use this provider you need to request the user email in your app" diff --git a/plugins/oauth_client/lib/oauth_client_plugin.rb b/plugins/oauth_client/lib/oauth_client_plugin.rb index d08738f..eb7dff0 100644 --- a/plugins/oauth_client/lib/oauth_client_plugin.rb +++ b/plugins/oauth_client/lib/oauth_client_plugin.rb @@ -31,13 +31,20 @@ class OauthClientPlugin < Noosfero::Plugin PROVIDERS = { :facebook => { - :name => 'Facebook' + :name => 'Facebook', + :info_fields => 'name,email' }, :google_oauth2 => { :name => 'Google' }, :noosfero_oauth2 => { :name => 'Noosfero' + }, + :github => { + :name => 'Github' + }, + :twitter => { + :name => 'Twitter' } } @@ -62,8 +69,9 @@ class OauthClientPlugin < Noosfero::Plugin provider_id = request.params['id'] provider_id ||= request.session['omniauth.params']['id'] if request.session['omniauth.params'] provider = environment.oauth_providers.find(provider_id) + strategy.options.merge! consumer_key: provider.client_id, consumer_secret: provider.client_secret strategy.options.merge! client_id: provider.client_id, client_secret: provider.client_secret - strategy.options.merge! provider.options.symbolize_keys + strategy.options.merge! options request.session[:provider_id] = provider_id } @@ -95,4 +103,8 @@ class OauthClientPlugin < Noosfero::Plugin } end + def js_files + ["script.js"] + end + end diff --git a/plugins/oauth_client/public/script.js b/plugins/oauth_client/public/script.js new file mode 100644 index 0000000..e89dae9 --- /dev/null +++ b/plugins/oauth_client/public/script.js @@ -0,0 +1,21 @@ +$(document).ready(function(){ + select_box_event(); +}); + +var toggle_info_message = function(){ + var selected_option = $("#oauth_client_plugin_provider_strategy option:selected"); + if (selected_option.length){ + if (selected_option.val() === "twitter"){ + $(".remember-enable-email").removeClass("hidden"); + } else { + $(".remember-enable-email").addClass("hidden"); + } + } +}; + +var select_box_event = function(){ + var select_box = $("#oauth_client_plugin_provider_strategy"); + select_box.on("change",function(){ + toggle_info_message(); + }); +}; diff --git a/plugins/oauth_client/public/style.css b/plugins/oauth_client/public/style.css index ae24d04..c9f3818 100644 --- a/plugins/oauth_client/public/style.css +++ b/plugins/oauth_client/public/style.css @@ -16,3 +16,7 @@ .oauth-login .provider .developer { display: none; } + +.remember-enable-email.hidden { + display: none; +} diff --git a/plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb b/plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb index 412c4a0..a028185 100644 --- a/plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb +++ b/plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb @@ -15,6 +15,10 @@ <%= labelled_form_field _('Strategy'), f.select(:strategy, OauthClientPlugin::PROVIDERS) %> +
+