diff --git a/Gemfile b/Gemfile
index 151158c69..812e6cdf9 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..0b5491901 100644
--- a/config/initializers/omniauth.rb
+++ b/config/initializers/omniauth.rb
@@ -46,4 +46,7 @@ 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'
+
end
diff --git a/db/migrate/20170924054554_weibo_oauth2.rb b/db/migrate/20170924054554_weibo_oauth2.rb
new file mode 100644
index 000000000..0ad4ba7bd
--- /dev/null
+++ b/db/migrate/20170924054554_weibo_oauth2.rb
@@ -0,0 +1,63 @@
+class WeiboOauth2 < ActiveRecord::Migration[4.2]
+ 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 e4dd649f9..fcd368959 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', 'Sina 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 @@
-
\ No newline at end of file
+
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 @@
+
+
\ 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