OpenID auth using Launchpad and Stackexchange works
This commit is contained in:
parent
2c135e1ca0
commit
4bad4d3a36
7 changed files with 38 additions and 86 deletions
|
|
@ -1,45 +1,24 @@
|
||||||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
|
|
||||||
# def passthru
|
# Workaround for https://github.com/plataformatec/devise/issues/2432
|
||||||
# raise
|
skip_before_filter :verify_authenticity_token
|
||||||
# send(params[:provider]) if providers.include?(params[:provider])
|
|
||||||
# end
|
|
||||||
|
|
||||||
def launchpad
|
def launchpad
|
||||||
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
login_via 'Launchpad'
|
||||||
@user = User.from_omniauth(request.env["omniauth.auth"])
|
|
||||||
|
|
||||||
if @user.persisted?
|
|
||||||
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Launchpad"
|
|
||||||
sign_in_and_redirect @user, :event => :authentication
|
|
||||||
else
|
|
||||||
# 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
|
end
|
||||||
|
|
||||||
def google_oauth2
|
def stackexchange
|
||||||
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
login_via 'StackExchange'
|
||||||
@user = User.from_omniauth(request.env["omniauth.auth"])
|
|
||||||
|
|
||||||
if @user.persisted?
|
|
||||||
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
|
|
||||||
sign_in_and_redirect @user, :event => :authentication
|
|
||||||
else
|
|
||||||
# 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
|
end
|
||||||
|
|
||||||
def amazon
|
def login_via(provider_name)
|
||||||
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
# You need to implement the method below in your model (e.g. app/models/user.rb)
|
||||||
@user = User.from_omniauth(request.env["omniauth.auth"])
|
@user = User.from_omniauth(request.env["omniauth.auth"])
|
||||||
|
|
||||||
if @user.persisted?
|
if @user.persisted?
|
||||||
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Amazon"
|
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => provider_name
|
||||||
sign_in_and_redirect @user, :event => :authentication
|
sign_in_and_redirect @user, :event => :authentication
|
||||||
else
|
else
|
||||||
# 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")
|
redirect_to new_user_session_url, alert: @user.errors.full_messages.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -48,9 +27,4 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# def providers
|
|
||||||
# ["twitter", "google_oauth2", "launchpad", "amazon"]
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,25 @@
|
||||||
class User < ApplicationRecord
|
class User < ApplicationRecord
|
||||||
|
|
||||||
# Include default devise modules. Others available are:
|
# Include default devise modules. Others available are:
|
||||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||||
devise :database_authenticatable,
|
devise :database_authenticatable,
|
||||||
# :registerable,
|
# :registerable,
|
||||||
:recoverable,
|
# :recoverable,
|
||||||
# :rememberable,
|
# :rememberable,
|
||||||
:trackable,
|
:trackable,
|
||||||
# :validatable,
|
# :validatable,
|
||||||
:timeoutable,
|
:timeoutable,
|
||||||
# :lockable,
|
# :lockable,
|
||||||
:omniauthable, :omniauth_providers => [:google_oauth2, :launchpad, :amazon]
|
:omniauthable, :omniauth_providers => [:launchpad,:stackexchange]
|
||||||
# :omniauthable, :omniauth_providers => [:launchpad, :google]
|
|
||||||
|
|
||||||
|
|
||||||
def self.from_omniauth(auth)
|
def self.from_omniauth(auth)
|
||||||
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
where(provider: auth.provider, email: auth.info.email).first_or_create do |user|
|
||||||
user.provider = auth.provider
|
user.provider = auth.provider
|
||||||
user.uid = auth.uid
|
user.uid = auth.uid
|
||||||
user.email = auth.info.email
|
user.email = auth.info.email
|
||||||
|
user.name = auth.info.name
|
||||||
|
# Set a random password
|
||||||
user.password = Devise.friendly_token[0,20]
|
user.password = Devise.friendly_token[0,20]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -38,13 +38,18 @@
|
||||||
/ = 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 Launchpad", user_launchpad_omniauth_authorize_path
|
||||||
|
= link_to "Sign in with StackExchange", user_stackexchange_omniauth_authorize_path
|
||||||
|
|
||||||
div
|
/ div
|
||||||
= link_to image_tag('/images/sso/google.png'), user_google_oauth2_omniauth_authorize_path
|
/ = link_to image_tag('/images/sso/google.png'), user_google_oauth2_omniauth_authorize_path
|
||||||
|
|
||||||
div
|
/ div
|
||||||
= link_to image_tag('/images/sso/amazon.png'), user_amazon_omniauth_authorize_path
|
/ = link_to "google new", user_google_omniauth_authorize_path
|
||||||
|
|
||||||
div
|
|
||||||
stackexchange
|
|
||||||
|
|
||||||
|
/
|
||||||
|
/ div
|
||||||
|
/ = link_to image_tag('/images/sso/amazon.png'), user_amazon_omniauth_authorize_path
|
||||||
|
/
|
||||||
|
/ div
|
||||||
|
/ stackexchange
|
||||||
|
/
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
// Show users' own uploaded screenshots in this session
|
|
||||||
|
|
||||||
/ = link_to 'Back', :back, class: 'button small'
|
|
||||||
|
|
||||||
.row.packagepage
|
|
||||||
h1 Screenshots you uploaded
|
|
||||||
|
|
||||||
- @packages.each do |package|
|
|
||||||
h2 Package #{package.name}
|
|
||||||
.subtitle
|
|
||||||
= package.description
|
|
||||||
|
|
||||||
.small-9.large-10.columns
|
|
||||||
- if @current_users_screenshots.length>0
|
|
||||||
.row.small-up-1.medium-up-3.large-up-4.grid-thumbnails
|
|
||||||
- @current_users_screenshots.each do |screenshot|
|
|
||||||
.column
|
|
||||||
|
|
||||||
a.black.fancybox href=screenshot.image.url(:large, timestamp: false)
|
|
||||||
div.grid-thumbnail
|
|
||||||
= image_tag(screenshot.image.url(:thumb, timestamp: false), alt: screenshot.caption, class: 'thumbnail')
|
|
||||||
div
|
|
||||||
= screenshot.description
|
|
||||||
|
|
@ -243,7 +243,7 @@ Devise.setup do |config|
|
||||||
# config.navigational_formats = ['*/*', :html]
|
# config.navigational_formats = ['*/*', :html]
|
||||||
|
|
||||||
# The default HTTP method used to sign out a resource. Default is :delete.
|
# The default HTTP method used to sign out a resource. Default is :delete.
|
||||||
config.sign_out_via = :delete
|
# config.sign_out_via = :delete
|
||||||
|
|
||||||
# ==> OmniAuth
|
# ==> OmniAuth
|
||||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||||
|
|
@ -274,23 +274,15 @@ Devise.setup do |config|
|
||||||
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
# config.omniauth_path_prefix = '/my_engine/users/auth'
|
||||||
|
|
||||||
# config.omniauth :launchpad, 'debshots'
|
# 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 :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 :amazon, 'amzn1.application-oa2-client.78d832919fc24456b0636762cf18efd9', '8c495d0940ca4100313c03e93b8b4240eef256d2fdbe672718506f29f5a20f61', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
|
||||||
|
|
||||||
# config.omniauth :launchpad, 'Debian Screenshots', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
|
config.omniauth :open_id, name: :stackexchange, identifier: 'https://openid.stackexchange.com', :client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
|
||||||
|
config.omniauth :open_id, name: :launchpad, identifier: 'https://login.ubuntu.com', :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" }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
# client_options: {ssl: {ca_path: '/etc/ssl/certs'}}
|
||||||
end
|
end
|
||||||
|
|
||||||
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ en:
|
||||||
subject: "Reset password instructions"
|
subject: "Reset password instructions"
|
||||||
unlock_instructions:
|
unlock_instructions:
|
||||||
subject: "Unlock instructions"
|
subject: "Unlock instructions"
|
||||||
|
email_changed:
|
||||||
|
subject: "Email Changed"
|
||||||
password_change:
|
password_change:
|
||||||
subject: "Password Changed"
|
subject: "Password Changed"
|
||||||
omniauth_callbacks:
|
omniauth_callbacks:
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ Debshots::Application.routes.draw do
|
||||||
get 'admin/integration'
|
get 'admin/integration'
|
||||||
|
|
||||||
devise_for :users, controllers: {
|
devise_for :users, controllers: {
|
||||||
registrations: "users/registrations",
|
# registrations: "users/registrations",
|
||||||
passwords: "users/passwords",
|
# passwords: "users/passwords",
|
||||||
omniauth_callbacks: "users/omniauth_callbacks"
|
omniauth_callbacks: "users/omniauth_callbacks"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue