Playing with OmniAuth

However OmniAuth is mainly used for authorization. So let's try a more
lightweight approach with just OpenID.
This commit is contained in:
Christoph Haas 2017-04-15 23:08:25 +02:00
parent 8d15711c0f
commit 898dd81c6b
15 changed files with 219 additions and 21 deletions

View file

@ -111,7 +111,7 @@ gem "font-awesome-rails"
# gem "recaptcha", require: "recaptcha/rails"
gem "sprockets", '3.6.3'
gem "sprockets"
#gem "activemodel-serializers-xml"
@ -120,7 +120,9 @@ gem 'omniauth'
gem 'omniauth-amazon'
gem 'omniauth-google-oauth2'
gem 'omniauth-github'
gem 'omniauth-twitter'
gem 'omniauth-facebook'
# gem 'omniauth-twitter'
gem 'omniauth-openid'
# gem 'omniauth-facebook'
# gem 'omniauth-launchpad' # is broken
gem 'omniauth-launchpad', :git => 'https://github.com/joaopapereira/omniauth-launchpad'
# gem 'omniauth-openid-connect'

View file

@ -183,8 +183,6 @@ GEM
omniauth-amazon (1.0.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-facebook (4.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-github (1.2.3)
omniauth (~> 1.5)
omniauth-oauth2 (>= 1.4.0, < 2.0)
@ -199,9 +197,9 @@ GEM
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1)
rack
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.5.0)
paperclip (5.1.0)
activemodel (>= 4.2.0)
@ -220,6 +218,9 @@ GEM
slop (~> 3.4)
puma (3.8.2)
rack (2.0.1)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-test (0.6.3)
rack (>= 1.0)
rails (5.0.2)
@ -259,6 +260,7 @@ GEM
responders (2.3.0)
railties (>= 4.2.0, < 5.1)
ruby-graphviz (1.2.3)
ruby-openid (2.7.0)
ruby-progressbar (1.8.1)
sass (3.4.23)
sass-rails (5.0.6)
@ -284,7 +286,7 @@ GEM
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
sprockets (3.6.3)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-es6 (0.9.2)
@ -344,11 +346,10 @@ DEPENDENCIES
minitest-reporters
omniauth
omniauth-amazon
omniauth-facebook
omniauth-github
omniauth-google-oauth2
omniauth-launchpad!
omniauth-twitter
omniauth-openid
paperclip
pg
pg_search
@ -360,7 +361,7 @@ DEPENDENCIES
slim-rails
spring
spring-watcher-listen (~> 2.0.0)
sprockets (= 3.6.3)
sprockets
therubyracer
turbolinks (~> 5)
uglifier (>= 1.3.0)

View file

@ -16,7 +16,6 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# session["devise.google_data"] = request.env["omniauth.auth"].except(:extra) #Removing extra as it can overflow some session stores
redirect_to new_user_session_url, alert: @user.errors.full_messages.join("\n")
end
end
def google_oauth2
@ -45,12 +44,12 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end
end
# def failure
# redirect_to root_path
# end
def failure
redirect_to root_path
end
private
# private
#
# def providers
# ["twitter", "google_oauth2", "launchpad", "amazon"]
# end

View file

@ -0,0 +1,5 @@
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

View file

@ -0,0 +1,3 @@
<p>Hello <%= @resource.email %>!</p>
<p>We're contacting you to notify you that your password has been changed.</p>

View file

@ -0,0 +1,8 @@
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

View file

@ -0,0 +1,7 @@
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>

View file

@ -0,0 +1,25 @@
<h2>Change your password</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.label :password, "New password" %><br />
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
<% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "devise/shared/links" %>

View file

@ -0,0 +1,16 @@
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>

View file

@ -0,0 +1,43 @@
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
<% end %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>

View file

@ -0,0 +1,29 @@
<h2>Sign up</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "devise/shared/links" %>

View file

@ -35,8 +35,16 @@
/ = link_to 'log in using your secure certificate', users_debian_sso_path
/ = link_to "Sign in with Launchpad", user_launchpad_omniauth_authorize_path
= link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path
/ = link_to "Sign in with Google", user_google_oauth2_omniauth_authorize_path
= link_to "Sign in with Launchpad", user_launchpad_omniauth_authorize_path
= link_to "Sign in with Amazon", user_amazon_omniauth_authorize_path
div
= link_to image_tag('/images/sso/google.png'), user_google_oauth2_omniauth_authorize_path
div
= link_to image_tag('/images/sso/amazon.png'), user_amazon_omniauth_authorize_path
div
stackexchange

View file

@ -0,0 +1,25 @@
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>

View file

@ -0,0 +1,16 @@
<h2>Resend unlock instructions</h2>
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "devise/shared/links" %>

View file

@ -276,10 +276,21 @@ Devise.setup do |config|
# config.omniauth :launchpad, 'debshots'
config.omniauth :google_oauth2, '398593918966-0fpmit0pb6ptio1ndsie5dfcnqhei63l.apps.googleusercontent.com', 'uRQq_dLs1kx7l5sYIyEyPVRc', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
config.omniauth :launchpad, 'Debian Screenshots', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
# config.omniauth :launchpad, 'Debian Screenshots', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
config.omniauth :amazon, 'amzn1.application-oa2-client.78d832919fc24456b0636762cf18efd9', '8c495d0940ca4100313c03e93b8b4240eef256d2fdbe672718506f29f5a20f61', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
config.omniauth :openid, :client_options => {
name: :launchpad,
identifier: 'https://login.ubuntu.com'
# # scope: [:openid, :email],
# response_type: :code,
# client_options: {
# port: 443,
# scheme: "https",
# host: "login.ubuntu.com" }
}
end
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE