diff --git a/app/models/user.rb b/app/models/user.rb index f86f8260..a63ebe18 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -101,8 +101,8 @@ class User < ApplicationRecord [:database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, - # omniauth_providers: [:suse, :google, :facebook, :github, :discourse] - omniauth_providers: [:google, :discourse] + omniauth_providers: [:suse, :google, :facebook, :github, :discourse] + # omniauth_providers: [:google, :discourse] ] end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 101f0c3d..ab9a2636 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -6,7 +6,7 @@ Devise.setup do |config| # Define the available openID providers that can be used to log in # Pass each provider to User model in :omniauth_providers (for open_id providers use their name) - # config.omniauth :open_id, name: 'suse', identifier: 'http://www.opensuse.org/openid/user' + config.omniauth :open_id, name: 'suse', identifier: 'http://www.opensuse.org/openid/user' config.omniauth :google_oauth2, (ENV['OSEM_GOOGLE_KEY'] || Rails.application.secrets.google_key), @@ -14,6 +14,7 @@ Devise.setup do |config| name: 'google', scope: 'email' + # TODO (snapcon): This ought to be configurable. Use OSEM_DISCOURSE_KEY? config.omniauth :discourse, sso_url: 'https://forum.snap.berkeley.edu/session/sso_provider', sso_secret: ENV['OSEM_DISCOURSE_SECRET'] diff --git a/spec/features/omniauth_spec.rb b/spec/features/omniauth_spec.rb index 3594bc32..df6f7728 100644 --- a/spec/features/omniauth_spec.rb +++ b/spec/features/omniauth_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -feature Openid do +feature Openid, type: :feature, js: true do shared_examples 'sign in with openid' do scenario 'has option to log in with Google account' do diff --git a/spec/support/omniauth_macros.rb b/spec/support/omniauth_macros.rb index a7ec88bb..11077f34 100644 --- a/spec/support/omniauth_macros.rb +++ b/spec/support/omniauth_macros.rb @@ -6,12 +6,16 @@ module OmniauthMacros ENV['OSEM_GOOGLE_KEY'] = 'test key google' ENV['OSEM_GOOGLE_SECRET'] = 'test secret google' - # ENV['OSEM_FACEBOOK_KEY'] = 'test key facebook' - # ENV['OSEM_FACEBOOK_SECRET'] = 'test secret facebook' - # ENV['OSEM_SUSE_KEY'] = 'test key suse' - # ENV['OSEM_SUSE_SECRET'] = 'test secret suse' - # ENV['OSEM_GITHUB_KEY'] = 'test key github' - # ENV['OSEM_GITHUB_SECRET'] = 'test secret github' + ENV['OSEM_FACEBOOK_KEY'] = 'test key facebook' + ENV['OSEM_FACEBOOK_SECRET'] = 'test secret facebook' + ENV['OSEM_SUSE_KEY'] = 'test key suse' + ENV['OSEM_SUSE_SECRET'] = 'test secret suse' + ENV['OSEM_GITHUB_KEY'] = 'test key github' + ENV['OSEM_GITHUB_SECRET'] = 'test secret github' + ENV['OSEM_DISCOURSE_KEY'] = 'test key discourse' + ENV['OSEM_DISCOURSE_SECRET'] = 'test secret discourse' + + def mock_auth_new_user OmniAuth.config.mock_auth[:google] = @@ -146,5 +150,20 @@ module OmniauthMacros secret: 'github_mock_secret' } ) + + OmniAuth.config.mock_auth[:discourse] = + OmniAuth::AuthHash.new( + provider: 'discourse', + uid: 'discourse-test-uid-1', + info: { + name: 'discourse user', + email: 'user-discourse@example.com', + username: 'user_discourse' + }, + credentials: { + token: 'discourse_mock_token', + secret: 'discourse_mock_secret' + } + ) end end