diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index 70e4b04..9ddeee3 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -3,29 +3,33 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController # Workaround for https://github.com/plataformatec/devise/issues/2432 # skip_before_filter :verify_authenticity_token - def launchpad - login_via 'Launchpad' + def salsa + login_via 'salsa.debian.org' end - def stackexchange - login_via 'StackExchange' - end + # def launchpad + # login_via 'Launchpad' + # end - def google_oauth2 - login_via 'Google' - end + # def stackexchange + # login_via 'StackExchange' + # end - def amazon - login_via 'Amazon' - end + # def google_oauth2 + # login_via 'Google' + # end - def github - login_via 'Github' - end + # def amazon + # login_via 'Amazon' + # end - def failure - redirect_to root_path - end + # def github + # login_via 'Github' + # end + + # def failure + # redirect_to root_path + # end def login_via(provider_name) # TODO: log diff --git a/app/models/user.rb b/app/models/user.rb index 8924fbc..b01ceb9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,29 +11,30 @@ class User < ApplicationRecord # :validatable, :timeoutable, # :lockable, - :omniauthable, :omniauth_providers => [ - :launchpad, - :stackexchange, - :google_oauth2, - :amazon, - :github + :omniauthable, omniauth_providers: [ + :salsa, + # :launchpad, + # :stackexchange, + # :google_oauth2, + # :amazon, + # :github ] # Return a human-friendly string describing the user's SSO provider def pretty_provider case self.provider - when 'launchpad' - 'Ubuntu One/Launchpad' - when 'stackexchange' - 'StackExchange' - when 'google_oauth2' - 'Google' - when 'amazon' - 'Amazon' - when 'github' - 'GitHub' - when 'debian-sso' - 'Debian single-sign-on' + # when 'launchpad' + # 'Ubuntu One/Launchpad' + # when 'stackexchange' + # 'StackExchange' + # when 'google_oauth2' + # 'Google' + # when 'amazon' + # 'Amazon' + # when 'github' + # 'GitHub' + when 'salsa' + 'salsa.debian.org' else 'local authentication' end diff --git a/app/views/devise/sessions/new.slim b/app/views/devise/sessions/new.slim index 990a2a5..6157b7f 100644 --- a/app/views/devise/sessions/new.slim +++ b/app/views/devise/sessions/new.slim @@ -28,9 +28,12 @@ / a href='https://sso.debian.org/' Debian SSO / ' installed in your browser. -/ .grid-container -/ .text-center - +.grid-container + .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.) / / p / / = link_to (fa_icon 'google', text: '- Login with Google'), user_google_oauth2_omniauth_authorize_path, class: 'button secondary large' diff --git a/app/views/my/profile.slim b/app/views/my/profile.slim index 1aa762f..77fcf81 100644 --- a/app/views/my/profile.slim +++ b/app/views/my/profile.slim @@ -30,3 +30,5 @@ - if current_user.is_admin? h2 Admin p Apparently you are an administrator. Be careful with that thing! + + tt = current_user.inspect diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index c7484a4..7f725cf 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -286,22 +286,44 @@ Devise.setup do |config| # config.omniauth_path_prefix = '/my_engine/users/auth' # 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', - :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'], + # Hint: https://salsa.debian.org/.well-known/openid-configuration + # Configuration: https://github.com/m0n9oose/omniauth_openid_connect + config.omniauth :openid_connect, { + name: :salsa, + scope: [:openid, :email, :profile], + discovery: true, + issuer: "https://salsa.debian.org", 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 # If your app is using Turbolinks, Turbolinks::Controller needs to be included to make redirection work correctly: # diff --git a/config/routes.rb b/config/routes.rb index 657eb24..c76e7fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ Rails.application.routes.draw do get 'admin/integration' + # https://www.rubydoc.info/github/plataformatec/devise/ActionDispatch%2FRouting%2FMapper:devise_for devise_for :users, controllers: { # registrations: "users/registrations", # passwords: "users/passwords",