From 336ac678984cb6b3057430c93364bb1c090018bd Mon Sep 17 00:00:00 2001 From: NeverMin Date: Tue, 26 Sep 2017 22:41:55 +0800 Subject: [PATCH 1/5] Closes #1465 --- Gemfile | 1 + .../_profile/linked_accounts.coffee | 5 ++ app/assets/stylesheets/svg-dimensions.css | 3 +- app/assets/stylesheets/zammad.scss | 4 ++ config/initializers/omniauth.rb | 7 +++ db/migrate/20170924054554_weibo.rb | 63 +++++++++++++++++++ db/seeds/settings.rb | 57 +++++++++++++++++ public/assets/images/icons.svg | 2 +- public/assets/images/icons/weibo-button.svg | 15 +++++ vendor/lib/weibo_database.rb | 13 ++++ 10 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170924054554_weibo.rb create mode 100644 public/assets/images/icons/weibo-button.svg create mode 100644 vendor/lib/weibo_database.rb diff --git a/Gemfile b/Gemfile index 81955ce14..7e5bd0fd8 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ gem 'omniauth-google-oauth2' gem 'omniauth-linkedin-oauth2' gem 'omniauth-twitter' gem 'omniauth-microsoft-office365' +gem 'omniauth-weibo-oauth2' gem 'twitter' gem 'telegramAPI' diff --git a/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee b/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee index 5f731803b..7e3a8b14c 100644 --- a/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee +++ b/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee @@ -95,4 +95,9 @@ App.Config.set('auth_provider_all', { name: 'OAuth2' config: 'auth_oauth2' class: 'oauth2' + weibo: + url: '/auth/weibo' + name: 'Weibo' + config: 'auth_weibo' + class: 'weibo' }) diff --git a/app/assets/stylesheets/svg-dimensions.css b/app/assets/stylesheets/svg-dimensions.css index d86c8b006..3fa27c806 100644 --- a/app/assets/stylesheets/svg-dimensions.css +++ b/app/assets/stylesheets/svg-dimensions.css @@ -56,6 +56,7 @@ .icon-note { width: 16px; height: 16px; } .icon-oauth2-button { width: 29px; height: 24px; } .icon-office365-button { width: 29px; height: 24px; } +.icon-weibo-button { width: 29px; height: 24px; } .icon-one-ticket { width: 48px; height: 10px; } .icon-organization { width: 16px; height: 16px; } .icon-outbound-calls { width: 17px; height: 17px; } @@ -97,4 +98,4 @@ .icon-user { width: 16px; height: 16px; } .icon-web { width: 17px; height: 17px; } .icon-zoom-in { width: 20px; height: 20px; } -.icon-zoom-out { width: 20px; height: 20px; } \ No newline at end of file +.icon-zoom-out { width: 20px; height: 20px; } diff --git a/app/assets/stylesheets/zammad.scss b/app/assets/stylesheets/zammad.scss index f99576096..6678c2d2a 100644 --- a/app/assets/stylesheets/zammad.scss +++ b/app/assets/stylesheets/zammad.scss @@ -2645,6 +2645,10 @@ ol.tabs li { background: hsl(15,100%,47%); } + &.auth-provider--weibo { + background: hsl(0,0%,27%); + } + .provider-name { flex: 1; } diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index ea2793497..daf75ac0b 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -46,4 +46,11 @@ Rails.application.config.middleware.use OmniAuth::Builder do }, } + # weibo database connect + provider :weibo_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database', { + token_params: { + redirect_uri: "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/auth/weibo/callback" + }, + } + end diff --git a/db/migrate/20170924054554_weibo.rb b/db/migrate/20170924054554_weibo.rb new file mode 100644 index 000000000..4463cf1f0 --- /dev/null +++ b/db/migrate/20170924054554_weibo.rb @@ -0,0 +1,63 @@ +class Weibo < ActiveRecord::Migration + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + Setting.create_if_not_exists( + title: 'Authentication via %s', + name: 'auth_weibo', + area: 'Security::ThirdPartyAuthentication', + description: 'Enables user authentication via %s. Register your app first at [%s](%s).', + options: { + form: [ + { + display: '', + null: true, + name: 'auth_weibo', + tag: 'boolean', + options: { + true => 'yes', + false => 'no', + }, + }, + ], + }, + preferences: { + controller: 'SettingsAreaSwitch', + sub: ['auth_weibo_credentials'], + title_i18n: ['Weibo'], + description_i18n: ['Weibo', 'Sina Weibo Open Portal', 'http://open.weibo.com'], + permission: ['admin.security'], + }, + state: false, + frontend: true + ) + Setting.create_if_not_exists( + title: 'Weibo App Credentials', + name: 'auth_weibo_credentials', + area: 'Security::ThirdPartyAuthentication::Weibo', + description: 'Enables user authentication via Sina Weibo.', + options: { + form: [ + { + display: 'App ID', + null: true, + name: 'app_id', + tag: 'input', + }, + { + display: 'App Secret', + null: true, + name: 'app_secret', + tag: 'input', + }, + ], + }, + state: {}, + preferences: { + permission: ['admin.security'], + }, + frontend: false + ) + end +end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 58745877e..261027b98 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -1274,6 +1274,63 @@ Setting.create_if_not_exists( frontend: false ) +Setting.create_if_not_exists( + title: 'Authentication via %s', + name: 'auth_weibo', + area: 'Security::ThirdPartyAuthentication', + description: 'Enables user authentication via %s. Register your app first at [%s](%s).', + options: { + form: [ + { + display: '', + null: true, + name: 'auth_weibo', + tag: 'boolean', + options: { + true => 'yes', + false => 'no', + }, + }, + ], + }, + preferences: { + controller: 'SettingsAreaSwitch', + sub: ['auth_weibo_credentials'], + title_i18n: ['Weibo'], + description_i18n: ['Sina Weibo', 'Weibo Open Protal', 'http://open.weibo.com'], + permission: ['admin.security'], + }, + state: false, + frontend: true +) +Setting.create_if_not_exists( + title: 'Weibo App Credentials', + name: 'auth_weibo_credentials', + area: 'Security::ThirdPartyAuthentication::Weibo', + description: 'Enables user authentication via Weibo.', + options: { + form: [ + { + display: 'App ID', + null: true, + name: 'client_id', + tag: 'input', + }, + { + display: 'App Secret', + null: true, + name: 'client_secret', + tag: 'input', + }, + ], + }, + state: {}, + preferences: { + permission: ['admin.security'], + }, + frontend: false +) + Setting.create_if_not_exists( title: 'Minimum length', name: 'password_min_size', diff --git a/public/assets/images/icons.svg b/public/assets/images/icons.svg index b4b8b1d0e..698cab350 100644 --- a/public/assets/images/icons.svg +++ b/public/assets/images/icons.svg @@ -1 +1 @@ -arrow-downarrow-leftarrow-rightarrow-upchatcheckbox-checkedcheckbox-indeterminatecheckboxcheckmarkclipboardclockcloudcogcrowndashboarddiagonal-crossdownloaddraggabledropdown-listemail-buttonemaileyedropperfacebook-buttonfacebookformgithub-buttongitlab-buttongoogle-buttongrouphelpimportantin-processinfoline-left-arrowline-right-arrowlinkedin-buttonlistloadinglock-openlocklogotypelong-arrow-rightmagnifiermarkermessageminus-smallminusmood-badmood-goodmood-okmood-superbadmood-supergoodmutenoteoauth2-buttonoffice365-buttonone-ticketorganizationoutbound-callsoverviewspackagepaperclippenpersonphoneplus-smallplusprinterradio-checkedradioreceived-callsreloadreopeningreply-allreplyreportsearchdetailsignoutsmall-dotsplitstatus-modified-outer-circlestatusstopwatchswitchViewtask-stateteamtelegramtemplatestoolstotal-ticketstrashtwitter-buttontwitterunmuteuserwebzoom-inzoom-out \ No newline at end of file +arrow-downarrow-leftarrow-rightarrow-upchatcheckbox-checkedcheckbox-indeterminatecheckboxcheckmarkclipboardclockcloudcogcrowndashboarddiagonal-crossdownloaddraggabledropdown-listemail-buttonemaileyedropperfacebook-buttonfacebookformgithub-buttongitlab-buttongoogle-buttongrouphelpimportantin-processinfoline-left-arrowline-right-arrowlinkedin-buttonlistloadinglock-openlocklogotypelong-arrow-rightmagnifiermarkermessageminus-smallminusmood-badmood-goodmood-okmood-superbadmood-supergoodmutenoteoauth2-buttonoffice365-buttonone-ticketorganizationoutbound-callsoverviewspackagepaperclippenpersonphoneplus-smallplusprinterradio-checkedradioreceived-callsreloadreopeningreply-allreplyreportsearchdetailsignoutsmall-dotsplitstatus-modified-outer-circlestatusstopwatchswitchViewtask-stateteamtelegramtemplatestoolstotal-ticketstrashtwitter-buttontwitterunmuteuserwebzoom-inzoom-outicon-weibo-buttonCreated with Sketch. diff --git a/public/assets/images/icons/weibo-button.svg b/public/assets/images/icons/weibo-button.svg new file mode 100644 index 000000000..16db76701 --- /dev/null +++ b/public/assets/images/icons/weibo-button.svg @@ -0,0 +1,15 @@ + + + + icon-weibo-button + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/vendor/lib/weibo_database.rb b/vendor/lib/weibo_database.rb new file mode 100644 index 000000000..6cc155dfd --- /dev/null +++ b/vendor/lib/weibo_database.rb @@ -0,0 +1,13 @@ +class WeiboDatabase < OmniAuth::Strategies::Weibo + option :name, 'weibo' + + def initialize(app, *args, &block) + + # database lookup + config = Setting.get('auth_weibo_credentials') || {} + args[0] = config['client_id'] + args[1] = config['client_secret'] + super + end + +end From ac4f8b777fbd4a0d47a720adac8e02a43cba3f8c Mon Sep 17 00:00:00 2001 From: NeverMin Date: Wed, 27 Sep 2017 14:12:10 +0800 Subject: [PATCH 2/5] small fix, added protal name --- db/seeds/settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 261027b98..29df51f7b 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -1297,7 +1297,7 @@ Setting.create_if_not_exists( controller: 'SettingsAreaSwitch', sub: ['auth_weibo_credentials'], title_i18n: ['Weibo'], - description_i18n: ['Sina Weibo', 'Weibo Open Protal', 'http://open.weibo.com'], + description_i18n: ['Sina Weibo', 'Sina Weibo Open Protal', 'http://open.weibo.com'], permission: ['admin.security'], }, state: false, From bf744ff0f0275ba9575124ab4542f90541503466 Mon Sep 17 00:00:00 2001 From: NeverMin Date: Thu, 28 Sep 2017 22:47:17 +0800 Subject: [PATCH 3/5] rename weibo db migrate filename --- .../{20170924054554_weibo.rb => 20170924054554_weibo_oauth2.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/migrate/{20170924054554_weibo.rb => 20170924054554_weibo_oauth2.rb} (100%) diff --git a/db/migrate/20170924054554_weibo.rb b/db/migrate/20170924054554_weibo_oauth2.rb similarity index 100% rename from db/migrate/20170924054554_weibo.rb rename to db/migrate/20170924054554_weibo_oauth2.rb From 952e648fb976285160bd3c22364539a89719d35a Mon Sep 17 00:00:00 2001 From: NeverMin Date: Fri, 29 Sep 2017 22:26:43 +0800 Subject: [PATCH 4/5] fixed weibo oauth2 db --- db/migrate/20170924054554_weibo_oauth2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20170924054554_weibo_oauth2.rb b/db/migrate/20170924054554_weibo_oauth2.rb index 4463cf1f0..0ad4ba7bd 100644 --- a/db/migrate/20170924054554_weibo_oauth2.rb +++ b/db/migrate/20170924054554_weibo_oauth2.rb @@ -1,4 +1,4 @@ -class Weibo < ActiveRecord::Migration +class WeiboOauth2 < ActiveRecord::Migration[4.2] def up # return if it's a new setup From 572cfc8ea4c3502291a2bb9d76e52350f4954fe2 Mon Sep 17 00:00:00 2001 From: NeverMin Date: Sat, 30 Sep 2017 16:21:16 +0800 Subject: [PATCH 5/5] fixed db migrate issue --- config/initializers/omniauth.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index daf75ac0b..0b5491901 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -47,10 +47,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do } # weibo database connect - provider :weibo_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database', { - token_params: { - redirect_uri: "#{Setting.get('http_type')}://#{Setting.get('fqdn')}/auth/weibo/callback" - }, - } + provider :weibo_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database' end