From 347423007a990625bcc4fc1d7336af0709c1f6e1 Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 30 Oct 2020 09:09:56 +0530 Subject: [PATCH] DEV: remove instagram login site settings and auth classes. (#11073) Instagram removed the support for login and should use Facebook login instead. --- Gemfile | 1 - Gemfile.lock | 4 -- .../common/components/buttons.scss | 6 -- config/locales/server.en.yml | 4 -- config/site_settings.yml | 9 --- lib/auth.rb | 1 - lib/auth/instagram_authenticator.rb | 20 ------- lib/discourse.rb | 1 - .../auth/instagram_authenticator_spec.rb | 60 ------------------- spec/jobs/old_keys_reminder_spec.rb | 6 +- spec/models/user_spec.rb | 4 +- 11 files changed, 5 insertions(+), 111 deletions(-) delete mode 100644 lib/auth/instagram_authenticator.rb delete mode 100644 spec/components/auth/instagram_authenticator_spec.rb diff --git a/Gemfile b/Gemfile index 68bb1a5ecf4..cb86d7e4bac 100644 --- a/Gemfile +++ b/Gemfile @@ -101,7 +101,6 @@ gem 'css_parser', require: false gem 'omniauth' gem 'omniauth-facebook' gem 'omniauth-twitter' -gem 'omniauth-instagram' gem 'omniauth-github' gem 'omniauth-oauth2', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 4a5a6c3df71..1e557f2f823 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -226,9 +226,6 @@ GEM jwt (>= 2.0) omniauth (>= 1.1.1) omniauth-oauth2 (>= 1.6) - omniauth-instagram (1.3.0) - omniauth (~> 1) - omniauth-oauth2 (~> 1) omniauth-oauth (1.1.0) oauth omniauth (~> 1.0) @@ -504,7 +501,6 @@ DEPENDENCIES omniauth-facebook omniauth-github omniauth-google-oauth2 - omniauth-instagram omniauth-oauth2 omniauth-twitter onebox diff --git a/app/assets/stylesheets/common/components/buttons.scss b/app/assets/stylesheets/common/components/buttons.scss index 1355589694d..e00d5c2876d 100644 --- a/app/assets/stylesheets/common/components/buttons.scss +++ b/app/assets/stylesheets/common/components/buttons.scss @@ -183,12 +183,6 @@ background: var(--google-hover); } } - &.instagram { - background: var(--instagram); - &:hover { - background: var(--instagram-hover); - } - } &.facebook { background: $facebook; &:hover { diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 41b388b2510..608a288af52 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1663,10 +1663,6 @@ en: twitter_consumer_key: "Consumer key for Twitter authentication, registered at https://developer.twitter.com/apps" twitter_consumer_secret: "Consumer secret for Twitter authentication, registered at https://developer.twitter.com/apps" - enable_instagram_logins: "Enable Instagram authentication, requires instagram_consumer_key and instagram_consumer_secret" - instagram_consumer_key: "Consumer key for Instagram authentication" - instagram_consumer_secret: "Consumer secret Instagram authentication" - enable_facebook_logins: "Enable Facebook authentication, requires facebook_app_id and facebook_app_secret. See Configuring Facebook login for Discourse." facebook_app_id: "App id for Facebook authentication and sharing, registered at https://developers.facebook.com/apps" facebook_app_secret: "App secret for Facebook authentication, registered at https://developers.facebook.com/apps" diff --git a/config/site_settings.yml b/config/site_settings.yml index ffe941e4734..b0ad977432d 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -386,15 +386,6 @@ login: default: "" regex: "^[\\w+-]+$" secret: true - enable_instagram_logins: - default: false - instagram_consumer_key: - default: "" - regex: "^[a-z0-9]+$" - instagram_consumer_secret: - default: "" - regex: "^[a-z0-9]+$" - secret: true enable_facebook_logins: default: false facebook_app_id: diff --git a/lib/auth.rb b/lib/auth.rb index 5febb7aedc1..f501d901574 100644 --- a/lib/auth.rb +++ b/lib/auth.rb @@ -10,5 +10,4 @@ require 'auth/facebook_authenticator' require 'auth/github_authenticator' require 'auth/twitter_authenticator' require 'auth/google_oauth2_authenticator' -require 'auth/instagram_authenticator' require 'auth/discord_authenticator' diff --git a/lib/auth/instagram_authenticator.rb b/lib/auth/instagram_authenticator.rb deleted file mode 100644 index b9ba5e8940e..00000000000 --- a/lib/auth/instagram_authenticator.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -class Auth::InstagramAuthenticator < Auth::ManagedAuthenticator - def name - "instagram" - end - - def enabled? - SiteSetting.enable_instagram_logins - end - - def register_middleware(omniauth) - omniauth.provider :instagram, - setup: lambda { |env| - strategy = env["omniauth.strategy"] - strategy.options[:client_id] = SiteSetting.instagram_consumer_key - strategy.options[:client_secret] = SiteSetting.instagram_consumer_secret - } - end -end diff --git a/lib/discourse.rb b/lib/discourse.rb index 862ed6857ff..7ac27fe8986 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -326,7 +326,6 @@ module Discourse Auth::AuthProvider.new(authenticator: Auth::GoogleOAuth2Authenticator.new, frame_width: 850, frame_height: 500), # Custom icon implemented in client Auth::AuthProvider.new(authenticator: Auth::GithubAuthenticator.new, icon: "fab-github"), Auth::AuthProvider.new(authenticator: Auth::TwitterAuthenticator.new, icon: "fab-twitter"), - Auth::AuthProvider.new(authenticator: Auth::InstagramAuthenticator.new, icon: "fab-instagram"), Auth::AuthProvider.new(authenticator: Auth::DiscordAuthenticator.new, icon: "fab-discord") ] diff --git a/spec/components/auth/instagram_authenticator_spec.rb b/spec/components/auth/instagram_authenticator_spec.rb deleted file mode 100644 index d78c632b19c..00000000000 --- a/spec/components/auth/instagram_authenticator_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Auth::InstagramAuthenticator do - - it "takes over account if email is supplied" do - auth = Auth::InstagramAuthenticator.new - - user = Fabricate(:user) - - auth_token = { - info: { email: user.email }, - uid: "123", - provider: "instagram" - } - - result = auth.after_authenticate(auth_token) - - expect(result.user.id).to eq(user.id) - - info = UserAssociatedAccount.find_by(provider_name: "instagram", user_id: user.id) - expect(info.info["email"]).to eq(user.email) - end - - it 'can connect to a different existing user account' do - authenticator = Auth::InstagramAuthenticator.new - user1 = Fabricate(:user) - user2 = Fabricate(:user) - - hash = { - info: { email: user1.email }, - uid: "100", - provider: "instagram" - } - - result = authenticator.after_authenticate(hash, existing_account: user2) - - expect(result.user.id).to eq(user2.id) - expect(UserAssociatedAccount.exists?(provider_name: "instagram", user_id: user1.id)).to eq(false) - expect(UserAssociatedAccount.exists?(provider_name: "instagram", user_id: user2.id)).to eq(true) - end - - context 'revoke' do - fab!(:user) { Fabricate(:user) } - let(:authenticator) { Auth::InstagramAuthenticator.new } - - it 'raises exception if no entry for user' do - expect { authenticator.revoke(user) }.to raise_error(Discourse::NotFound) - end - - it 'revokes correctly' do - UserAssociatedAccount.create!(provider_name: "instagram", user_id: user.id, provider_uid: 100) - expect(authenticator.can_revoke?).to eq(true) - expect(authenticator.revoke(user)).to eq(true) - expect(authenticator.description_for_user(user)).to eq("") - end - end - -end diff --git a/spec/jobs/old_keys_reminder_spec.rb b/spec/jobs/old_keys_reminder_spec.rb index fe68070f996..bcbb2523669 100644 --- a/spec/jobs/old_keys_reminder_spec.rb +++ b/spec/jobs/old_keys_reminder_spec.rb @@ -4,7 +4,7 @@ require "rails_helper" describe Jobs::OldKeysReminder do let!(:google_secret) { SiteSetting.create!(name: 'google_oauth2_client_secret', value: '123', data_type: 1) } - let!(:instagram_secret) { SiteSetting.create!(name: 'instagram_consumer_secret', value: '123', data_type: 1) } + let!(:github_secret) { SiteSetting.create!(name: 'github_client_secret', value: '123', data_type: 1) } let!(:api_key) { Fabricate(:api_key, description: 'api key description') } let!(:admin) { Fabricate(:admin) } let!(:another_admin) { Fabricate(:admin) } @@ -31,7 +31,7 @@ Hello! This is a routine yearly security reminder from your Discourse instance. As a courtesy, we wanted to let you know that the following credentials used on your Discourse instance have not been updated in more than two years: google_oauth2_client_secret - #{google_secret.updated_at.to_date.to_s(:db)} -instagram_consumer_secret - #{instagram_secret.updated_at.to_date.to_s(:db)} +github_client_secret - #{github_secret.updated_at.to_date.to_s(:db)} api key description - #{api_key.created_at.to_date.to_s(:db)} No action is required at this time, however, it is considered good security practice to cycle all your important credentials every few years. @@ -48,7 +48,7 @@ Hello! This is a routine yearly security reminder from your Discourse instance. As a courtesy, we wanted to let you know that the following credentials used on your Discourse instance have not been updated in more than two years: google_oauth2_client_secret - #{google_secret.updated_at.to_date.to_s(:db)} -instagram_consumer_secret - #{instagram_secret.updated_at.to_date.to_s(:db)} +github_client_secret - #{github_secret.updated_at.to_date.to_s(:db)} twitter_consumer_secret - #{recent_twitter_secret.updated_at.to_date.to_s(:db)} api key description - #{api_key.created_at.to_date.to_s(:db)} recent api key description - #{admin.username} - #{recent_api_key.created_at.to_date.to_s(:db)} diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c530fc67ee1..7203680ac3d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -514,12 +514,12 @@ describe User do UserAssociatedAccount.create(user_id: user.id, provider_name: "twitter", provider_uid: "1", info: { nickname: "sam" }) UserAssociatedAccount.create(user_id: user.id, provider_name: "facebook", provider_uid: "1234", info: { email: "test@example.com" }) - UserAssociatedAccount.create(user_id: user.id, provider_name: "instagram", provider_uid: "examplel123123", info: { nickname: "sam" }) + UserAssociatedAccount.create(user_id: user.id, provider_name: "discord", provider_uid: "examplel123123", info: { nickname: "sam" }) UserAssociatedAccount.create(user_id: user.id, provider_name: "google_oauth2", provider_uid: "1", info: { email: "sam@sam.com" }) GithubUserInfo.create(user_id: user.id, screen_name: "sam", github_user_id: 1) user.reload - expect(user.associated_accounts.map { |a| a[:name] }).to contain_exactly('twitter', 'facebook', 'google_oauth2', 'github', 'instagram') + expect(user.associated_accounts.map { |a| a[:name] }).to contain_exactly('twitter', 'facebook', 'google_oauth2', 'github', 'discord') end end