Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OmniAuth login with Decidim.Barcelona button and strategy #57

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/node_modules
/yarn-error.log

.rbenv-vars
.byebug_history

# Ignore public uploads
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem "decidim", DECIDIM_VERSION
gem "decidim-initiatives", DECIDIM_VERSION
gem "decidim-consultations", DECIDIM_VERSION
gem "decidim-conferences", DECIDIM_VERSION
gem "omniauth-decidim", git: "https://github.com/decidim/omniauth-decidim"

gem "puma", "~> 3"
gem "uglifier"
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ GIT
decidim-verifications (0.19.0)
decidim-core (= 0.19.0)

GIT
remote: https://github.com/decidim/omniauth-decidim
revision: 2b7d087f1b581e06cc82b7716d09cc50e1d0e643
specs:
omniauth-decidim (0.1.0)
omniauth (~> 1.5)
omniauth-oauth2 (>= 1.4.0, < 2.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -831,6 +839,7 @@ DEPENDENCIES
listen (~> 3.1.0)
lograge
newrelic_rpm
omniauth-decidim!
passenger
platform-api
puma (~> 3)
Expand Down
118 changes: 118 additions & 0 deletions app/assets/images/icon-barcelona.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
* It is generally better to create a new file per style scope.
*
*= require decidim
*= require_tree .
*= require_tree ./custom
*= require_self
*/
27 changes: 27 additions & 0 deletions app/assets/stylesheets/custom/omniauth_buttons.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Ajustements for Decidim (login with Barcelona) login button
.button--social.button--decidim {
.button--social__icon {
padding-top: 0.7rem;
padding-bottom: 0.5rem;
svg {
width: auto;
height: 32px;
}
}
}

@media(max-width: 372px) {
.button--social.button--decidim {
padding: 0.5rem 1rem 0.5rem 3.7rem;
min-height: 3rem;
position: relative;
line-height: 1rem;

.button--social__icon {
position: absolute;
left:0;
top:0;
padding: 0.5em 0.5em;
}
}
}
23 changes: 23 additions & 0 deletions app/views/decidim/devise/shared/_omniauth_buttons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% if Devise.mappings[:user].omniauthable? && any_social_provider_enabled? %>
<div class="row">
<div class="columns large-4 mediumlarge-6 medium-8 medium-centered">
<%- Decidim::User.omniauth_providers.each do |provider| %>
<% if social_provider_enabled? provider %>
<div class="social-register">
<%= link_to decidim.send("user_#{provider}_omniauth_authorize_path"), class: "button button--social button--#{normalize_provider_name(provider)}", method: :post do %>
<span class="button--social__icon">
<%= oauth_icon provider %>
</span>
<%= t("devise.shared.links.sign_in_with_provider", provider: normalize_provider_name(provider).titleize) %><%= ('.Barcelona' if provider.to_s == 'decidim') %>
<% end %>
</div>
<% end %>
<% end %>
<%- if current_organization.sign_in_enabled? %>
<span class="register__separator">
<span class="register__separator__text"><%= t(".or") %></span>
</span>
<%- end %>
</div>
</div>
<% end %>
13 changes: 13 additions & 0 deletions config/initializers/omniauth_decidim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

if Rails.application.secrets.dig(:omniauth, :decidim, :enabled)
Devise.setup do |config|
config.omniauth :decidim,
Rails.application.secrets.dig(:omniauth, :decidim, :client_id),
Rails.application.secrets.dig(:omniauth, :decidim, :client_secret),
Rails.application.secrets.dig(:omniauth, :decidim, :site_url),
scope: :public
end
Decidim::User.omniauth_providers << :decidim

end
13 changes: 12 additions & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ default: &default
enabled: false
client_id: <%= ENV["OMNIAUTH_GOOGLE_CLIENT_ID"] %>
client_secret: <%= ENV["OMNIAUTH_GOOGLE_CLIENT_SECRET"] %>
decidim:
enabled: true
client_id: <%= ENV["OMNIAUTH_DECIDIM_CLIENT_ID"] %>
client_secret: <%= ENV["OMNIAUTH_DECIDIM_CLIENT_SECRET"] %>
site_url: "https://www.decidim.barcelona"
icon_path: icon-barcelona.svg
geocoder:
here_app_id: <%= ENV["GEOCODER_LOOKUP_APP_ID"] %>
here_app_code: <%= ENV["GEOCODER_LOOKUP_APP_CODE"] %>
Expand All @@ -42,7 +48,12 @@ development:
omniauth:
developer:
enabled: true

decidim:
enabled: true
client_id: <%= ENV["OMNIAUTH_DECIDIM_CLIENT_ID"] %>
client_secret: <%= ENV["OMNIAUTH_DECIDIM_CLIENT_SECRET"] %>
site_url: "https://www.decidim.barcelona"
icon_path: icon-barcelona.svg
test:
<<: *default
secret_key_base: 37d4a6caf41586fef44b7f2a744d70439803deb93efa2795552fa427c89bd3dc99c26e44a8dc8880819e7f00853b41bd77255ee8226f01ca32f69fc1ffc3c0cc
Expand Down