diff --git a/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee b/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee
index dc6b76911..0c1fbbb7d 100644
--- a/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee
+++ b/app/assets/javascripts/app/controllers/_profile/linked_accounts.coffee
@@ -11,34 +11,45 @@ class Index extends App.ControllerSubContent
render: =>
auth_provider_all = {
facebook: {
- key: 'facebook'
- url: '/auth/facebook',
- name: 'Facebook',
- config: 'auth_facebook',
+ url: '/auth/facebook'
+ name: 'Facebook'
+ config: 'auth_facebook'
},
twitter: {
- key: 'twitter'
- url: '/auth/twitter',
- name: 'Twitter',
- config: 'auth_twitter',
+ url: '/auth/twitter'
+ name: 'Twitter'
+ config: 'auth_twitter'
},
linkedin: {
- key: 'linkedin'
- url: '/auth/linkedin',
- name: 'LinkedIn',
- config: 'auth_linkedin',
+ url: '/auth/linkedin'
+ name: 'LinkedIn'
+ config: 'auth_linkedin'
+ },
+ github: {
+ url: '/auth/github'
+ name: 'GitHub'
+ config: 'auth_github'
+ },
+ gitlab: {
+ url: '/auth/gitlab'
+ name: 'GitLab'
+ config: 'auth_gitlab'
},
google_oauth2: {
- key: 'google_oauth2'
- url: '/auth/google_oauth2',
- name: 'Google',
- config: 'auth_google_oauth2',
+ url: '/auth/google_oauth2'
+ name: 'Google'
+ config: 'auth_google_oauth2'
+ },
+ oauth2: {
+ url: '/auth/oauth2'
+ name: 'OAuth2'
+ config: 'auth_oauth2'
},
}
- auth_providers = []
+ auth_providers = {}
for key, provider of auth_provider_all
if @Config.get(provider.config) is true || @Config.get(provider.config) is 'true'
- auth_providers.push provider
+ auth_providers[key] = provider
@html App.view('profile/linked_accounts')(
user: App.Session.get()
@@ -54,7 +65,7 @@ class Index extends App.ControllerSubContent
@ajax(
id: 'account'
type: 'DELETE'
- url: @apiPath + '/users/account'
+ url: "#{@apiPath}/users/account"
data: JSON.stringify(provider: provider, uid: uid)
processData: true
success: @success
diff --git a/app/assets/javascripts/app/controllers/login.coffee b/app/assets/javascripts/app/controllers/login.coffee
index ed3c580a8..f3111bd88 100644
--- a/app/assets/javascripts/app/controllers/login.coffee
+++ b/app/assets/javascripts/app/controllers/login.coffee
@@ -40,9 +40,9 @@ class Index extends App.ControllerContent
render: (data = {}) ->
auth_provider_all = {
facebook: {
- url: '/auth/facebook'
- name: 'Facebook'
- config: 'auth_facebook'
+ url: '/auth/facebook',
+ name: 'Facebook',
+ config: 'auth_facebook',
class: 'facebook'
},
twitter: {
@@ -59,13 +59,13 @@ class Index extends App.ControllerContent
},
github: {
url: '/auth/github'
- name: 'Github'
+ name: 'GitHub'
config: 'auth_github'
class: 'github'
},
gitlab: {
url: '/auth/gitlab'
- name: 'Gitlab'
+ name: 'GitLab'
config: 'auth_gitlab'
class: 'gitlab'
},
@@ -75,6 +75,12 @@ class Index extends App.ControllerContent
config: 'auth_google_oauth2'
class: 'google'
},
+ oauth2: {
+ url: '/auth/oauth2'
+ name: 'OAuth2'
+ config: 'auth_oauth2'
+ class: 'oauth2'
+ },
}
auth_providers = []
for key, provider of auth_provider_all
diff --git a/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco b/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco
index a056a8c9c..4f184ad97 100644
--- a/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco
+++ b/app/assets/javascripts/app/views/profile/linked_accounts.jst.eco
@@ -5,10 +5,12 @@
- <% for auth_provider in @auth_providers: %>
- - <%- @T( auth_provider.name ) %>
- <% if !@user['accounts'] || !@user['accounts'][auth_provider.key]: %><%- @T('Add') %>
- <% else: %>"<%= @user['accounts'][auth_provider.key]['username'] %>" <%- @T('remove') %>
+ <% for key, provider of @auth_providers: %>
+
- <%- @T( provider.name ) %>
+ <% if !@user['accounts'] || !@user['accounts'][key]: %>
+ <%- @T('Add') %>
+ <% else: %>
+ "<%= @user['accounts'][key]['username'] %>" <%- @T('remove') %>
<% end %>
<% end %>
diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb
index 94c16be9a..6436d6aad 100644
--- a/config/initializers/omniauth.rb
+++ b/config/initializers/omniauth.rb
@@ -1,17 +1,47 @@
Rails.application.config.middleware.use OmniAuth::Builder do
# twitter database connect
- provider :twitter_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse',
- client_options: { authorize_path: '/oauth/authorize', site: 'https://api.twitter.com' }
+ provider :twitter_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database', {
+ client_options: {
+ authorize_path: '/oauth/authorize',
+ site: 'https://api.twitter.com',
+ }
+ }
# facebook database connect
- provider :facebook_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse'
+ provider :facebook_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database'
# linkedin database connect
- provider :linked_in_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse'
+ provider :linked_in_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database'
# google database connect
- provider :google_oauth2_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse',
- authorize_options: { access_type: 'online', approval_prompt: '' }
+ provider :google_oauth2_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database', {
+ authorize_options: {
+ access_type: 'online',
+ approval_prompt: '',
+ }
+ }
+
+ # github database connect
+ provider :github_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database'
+
+ # gitlab database connect
+ provider :gitlab_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database', {
+ client_options: {
+ site: 'https://not_change_will_be_set_by_database',
+ authorize_url: '/oauth/authorize',
+ token_url: '/oauth/token'
+ },
+ scope: 'read_user',
+ }
+
+ # oauth2 database connect
+ provider :oauth2_database, 'not_change_will_be_set_by_database', 'not_change_will_be_set_by_database', {
+ client_options: {
+ site: 'https://not_change_will_be_set_by_database',
+ authorize_url: '/oauth/authorize',
+ token_url: '/oauth/token',
+ },
+ }
end
diff --git a/vendor/lib/github_database.rb b/vendor/lib/github_database.rb
new file mode 100644
index 000000000..3b4fe78a8
--- /dev/null
+++ b/vendor/lib/github_database.rb
@@ -0,0 +1,13 @@
+class GithubDatabase < OmniAuth::Strategies::GitHub
+ option :name, 'github'
+
+ def initialize(app, *args, &block)
+
+ # database lookup
+ config = Setting.get('auth_github_credentials') || {}
+ args[0] = config['app_id']
+ args[1] = config['app_secret']
+ super
+ end
+
+end
diff --git a/vendor/lib/gitlab_database.rb b/vendor/lib/gitlab_database.rb
new file mode 100644
index 000000000..799f06e90
--- /dev/null
+++ b/vendor/lib/gitlab_database.rb
@@ -0,0 +1,14 @@
+class GitlabDatabase < OmniAuth::Strategies::GitLab
+ option :name, 'gitlab'
+
+ def initialize(app, *args, &block)
+
+ # database lookup
+ config = Setting.get('auth_gitlab_credentials') || {}
+ args[0] = config['app_id']
+ args[1] = config['app_secret']
+ args[2][:client_options] = args[2][:client_options].merge(config.symbolize_keys)
+ super
+ end
+
+end
diff --git a/vendor/lib/oauth2_database.rb b/vendor/lib/oauth2_database.rb
new file mode 100644
index 000000000..09d656c90
--- /dev/null
+++ b/vendor/lib/oauth2_database.rb
@@ -0,0 +1,14 @@
+class Oauth2Database < OmniAuth::Strategies::OAuth2
+ option :name, 'oauth2'
+
+ def initialize(app, *args, &block)
+
+ # database lookup
+ config = Setting.get('auth_oauth2_credentials') || {}
+ args[0] = config['app_id']
+ args[1] = config['app_secret']
+ args[2][:client_options] = args[2][:client_options].merge(config.symbolize_keys)
+ super
+ end
+
+end