Salsa login works

This commit is contained in:
Christoph Haas 2021-02-27 23:50:51 +01:00
parent b2ed771663
commit bc507cbe39
6 changed files with 84 additions and 51 deletions

View file

@ -3,29 +3,33 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# Workaround for https://github.com/plataformatec/devise/issues/2432 # Workaround for https://github.com/plataformatec/devise/issues/2432
# skip_before_filter :verify_authenticity_token # skip_before_filter :verify_authenticity_token
def launchpad def salsa
login_via 'Launchpad' login_via 'salsa.debian.org'
end end
def stackexchange # def launchpad
login_via 'StackExchange' # login_via 'Launchpad'
end # end
def google_oauth2 # def stackexchange
login_via 'Google' # login_via 'StackExchange'
end # end
def amazon # def google_oauth2
login_via 'Amazon' # login_via 'Google'
end # end
def github # def amazon
login_via 'Github' # login_via 'Amazon'
end # end
def failure # def github
redirect_to root_path # login_via 'Github'
end # end
# def failure
# redirect_to root_path
# end
def login_via(provider_name) def login_via(provider_name)
# TODO: log # TODO: log

View file

@ -11,29 +11,30 @@ class User < ApplicationRecord
# :validatable, # :validatable,
:timeoutable, :timeoutable,
# :lockable, # :lockable,
:omniauthable, :omniauth_providers => [ :omniauthable, omniauth_providers: [
:launchpad, :salsa,
:stackexchange, # :launchpad,
:google_oauth2, # :stackexchange,
:amazon, # :google_oauth2,
:github # :amazon,
# :github
] ]
# Return a human-friendly string describing the user's SSO provider # Return a human-friendly string describing the user's SSO provider
def pretty_provider def pretty_provider
case self.provider case self.provider
when 'launchpad' # when 'launchpad'
'Ubuntu One/Launchpad' # 'Ubuntu One/Launchpad'
when 'stackexchange' # when 'stackexchange'
'StackExchange' # 'StackExchange'
when 'google_oauth2' # when 'google_oauth2'
'Google' # 'Google'
when 'amazon' # when 'amazon'
'Amazon' # 'Amazon'
when 'github' # when 'github'
'GitHub' # 'GitHub'
when 'debian-sso' when 'salsa'
'Debian single-sign-on' 'salsa.debian.org'
else else
'local authentication' 'local authentication'
end end

View file

@ -28,9 +28,12 @@
/ a href='https://sso.debian.org/' Debian SSO / a href='https://sso.debian.org/' Debian SSO
/ ' installed in your browser. / ' installed in your browser.
/ .grid-container .grid-container
/ .text-center .text-center
p
= link_to (fa_icon 'login', text: 'Login with Debian'), user_salsa_omniauth_authorize_path, class: 'button primary large', method: :post
/ // Alternative way to display buttons without images. (Amazon wants their own button though.) / // Alternative way to display buttons without images. (Amazon wants their own button though.)
/ / p / / p
/ / = link_to (fa_icon 'google', text: '- Login with Google'), user_google_oauth2_omniauth_authorize_path, class: 'button secondary large' / / = link_to (fa_icon 'google', text: '- Login with Google'), user_google_oauth2_omniauth_authorize_path, class: 'button secondary large'

View file

@ -30,3 +30,5 @@
- if current_user.is_admin? - if current_user.is_admin?
h2 Admin h2 Admin
p Apparently you are an administrator. Be careful with that thing! p Apparently you are an administrator. Be careful with that thing!
tt = current_user.inspect

View file

@ -286,22 +286,44 @@ 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, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
:client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}}
config.omniauth :open_id, name: :stackexchange, identifier: 'https://openid.stackexchange.com', # Hint: https://salsa.debian.org/.well-known/openid-configuration
:client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}} # Configuration: https://github.com/m0n9oose/omniauth_openid_connect
config.omniauth :openid_connect, {
config.omniauth :open_id, name: :launchpad, identifier: 'https://login.ubuntu.com', name: :salsa,
:client_options => {:ssl => {:ca_path => '/etc/ssl/certs'}} scope: [:openid, :email, :profile],
discovery: true,
config.omniauth :amazon, ENV['AMAZON_CLIENT_ID'], ENV['AMAZON_CLIENT_SECRET'], :client_options => issuer: "https://salsa.debian.org",
{:ssl => {:ca_path => '/etc/ssl/certs'}}
config.omniauth :github, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'],
client_options: { client_options: {
ssl: { ca_path: '/etc/ssl/certs' } port: 443,
scheme: "https",
host: "salsa.debian.org",
identifier: ENV['GITLAB_OAUTH_KEY'],
secret: ENV['GITLAB_OAUTH_SECRET'],
redirect_uri: "http://localhost:3000/users/auth/salsa/callback",
ssl: { ca_path: '/etc/ssl/certs'}
} }
}
OpenIDConnect.logger = Rails.logger
OmniAuth.config.logger = Rails.logger if Rails.env.development?
# config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
# :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, ENV['AMAZON_CLIENT_ID'], ENV['AMAZON_CLIENT_SECRET'], :client_options =>
# {:ssl => {:ca_path => '/etc/ssl/certs'}}
# config.omniauth :github, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_CLIENT_SECRET'],
# client_options: {
# ssl: { ca_path: '/etc/ssl/certs' }
# }
# ==> Turbolinks configuration # ==> Turbolinks configuration
# If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly:
# #

View file

@ -7,6 +7,7 @@ Rails.application.routes.draw do
get 'admin/integration' get 'admin/integration'
# https://www.rubydoc.info/github/plataformatec/devise/ActionDispatch%2FRouting%2FMapper:devise_for
devise_for :users, controllers: { devise_for :users, controllers: {
# registrations: "users/registrations", # registrations: "users/registrations",
# passwords: "users/passwords", # passwords: "users/passwords",