[Git][noosfero/noosfero][master] 2 commits: Add new providers facebook and twitter
Larissa Reis
gitlab at mg.gitlab.com
Mon Jun 20 17:29:10 BRT 2016
Larissa Reis pushed to branch master at Noosfero / noosfero
Commits:
070e0a7c by Thiago Ribeiro at 2016-06-16T17:20:09-03:00
Add new providers facebook and twitter
- Update facebook provider because facebook changing their API
- Add github provider
- Add twitter provider
- Update README
Signed-off-by: Gustavo Jaruga Cruz <darksshades at gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza at gmail.com>
Signed-off-by: Alessandro Caetano <alesasndro.caetanob at gmail.com>
- - - - -
7bdb0c8b by Larissa Reis at 2016-06-20T17:22:16-03:00
Add new providers facebook and twitter
- Update facebook provider because facebook changing their API
- Add github provider
- Add twitter provider
- Update README
Signed-off-by: Gustavo Jaruga Cruz <darksshades at gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza at gmail.com>
Signed-off-by: Alessandro Caetano <alesasndro.caetanob at gmail.com>
See merge request !965
- - - - -
7 changed files:
- plugins/oauth_client/Gemfile
- plugins/oauth_client/README.md
- + plugins/oauth_client/features/create_provider.feature
- plugins/oauth_client/lib/oauth_client_plugin.rb
- + plugins/oauth_client/public/script.js
- plugins/oauth_client/public/style.css
- plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb
Changes:
=====================================
plugins/oauth_client/Gemfile
=====================================
--- 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'
=====================================
plugins/oauth_client/README.md
=====================================
--- 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
========
=====================================
plugins/oauth_client/features/create_provider.feature
=====================================
--- /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"
=====================================
plugins/oauth_client/lib/oauth_client_plugin.rb
=====================================
--- 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
=====================================
plugins/oauth_client/public/script.js
=====================================
--- /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();
+ });
+};
=====================================
plugins/oauth_client/public/style.css
=====================================
--- 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;
+}
=====================================
plugins/oauth_client/views/oauth_client_plugin_admin/edit.html.erb
=====================================
--- 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) %>
</div>
+ <div class="remember-enable-email hidden">
+ <span class="error"><%=_('To use this provider you need to request the user email in your app')%></span>
+ </div>
+
<div class="client-id">
<%= labelled_form_field _('Client Id'), f.text_field(:client_id) %>
</div>
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/3c41ae142f01a9aac524149665e223f629db14c0...7bdb0c8bfcf8aaa13576cfb2dc62fdbc151ea25f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160620/2405d49e/attachment-0001.html>
More information about the Noosfero-dev
mailing list