Fixed issue #596 - Gitlab Auth not working.

This commit is contained in:
Martin Edenhofer 2017-01-10 22:14:02 +01:00
parent d36570aef0
commit 9e00143134
7 changed files with 124 additions and 34 deletions

View file

@ -11,34 +11,45 @@ class Index extends App.ControllerSubContent
render: => render: =>
auth_provider_all = { auth_provider_all = {
facebook: { facebook: {
key: 'facebook' url: '/auth/facebook'
url: '/auth/facebook', name: 'Facebook'
name: 'Facebook', config: 'auth_facebook'
config: 'auth_facebook',
}, },
twitter: { twitter: {
key: 'twitter' url: '/auth/twitter'
url: '/auth/twitter', name: 'Twitter'
name: 'Twitter', config: 'auth_twitter'
config: 'auth_twitter',
}, },
linkedin: { linkedin: {
key: 'linkedin' url: '/auth/linkedin'
url: '/auth/linkedin', name: 'LinkedIn'
name: 'LinkedIn', config: 'auth_linkedin'
config: 'auth_linkedin', },
github: {
url: '/auth/github'
name: 'GitHub'
config: 'auth_github'
},
gitlab: {
url: '/auth/gitlab'
name: 'GitLab'
config: 'auth_gitlab'
}, },
google_oauth2: { google_oauth2: {
key: 'google_oauth2' url: '/auth/google_oauth2'
url: '/auth/google_oauth2', name: 'Google'
name: 'Google', config: 'auth_google_oauth2'
config: 'auth_google_oauth2', },
oauth2: {
url: '/auth/oauth2'
name: 'OAuth2'
config: 'auth_oauth2'
}, },
} }
auth_providers = [] auth_providers = {}
for key, provider of auth_provider_all for key, provider of auth_provider_all
if @Config.get(provider.config) is true || @Config.get(provider.config) is 'true' 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')( @html App.view('profile/linked_accounts')(
user: App.Session.get() user: App.Session.get()
@ -54,7 +65,7 @@ class Index extends App.ControllerSubContent
@ajax( @ajax(
id: 'account' id: 'account'
type: 'DELETE' type: 'DELETE'
url: @apiPath + '/users/account' url: "#{@apiPath}/users/account"
data: JSON.stringify(provider: provider, uid: uid) data: JSON.stringify(provider: provider, uid: uid)
processData: true processData: true
success: @success success: @success

View file

@ -40,9 +40,9 @@ class Index extends App.ControllerContent
render: (data = {}) -> render: (data = {}) ->
auth_provider_all = { auth_provider_all = {
facebook: { facebook: {
url: '/auth/facebook' url: '/auth/facebook',
name: 'Facebook' name: 'Facebook',
config: 'auth_facebook' config: 'auth_facebook',
class: 'facebook' class: 'facebook'
}, },
twitter: { twitter: {
@ -59,13 +59,13 @@ class Index extends App.ControllerContent
}, },
github: { github: {
url: '/auth/github' url: '/auth/github'
name: 'Github' name: 'GitHub'
config: 'auth_github' config: 'auth_github'
class: 'github' class: 'github'
}, },
gitlab: { gitlab: {
url: '/auth/gitlab' url: '/auth/gitlab'
name: 'Gitlab' name: 'GitLab'
config: 'auth_gitlab' config: 'auth_gitlab'
class: 'gitlab' class: 'gitlab'
}, },
@ -75,6 +75,12 @@ class Index extends App.ControllerContent
config: 'auth_google_oauth2' config: 'auth_google_oauth2'
class: 'google' class: 'google'
}, },
oauth2: {
url: '/auth/oauth2'
name: 'OAuth2'
config: 'auth_oauth2'
class: 'oauth2'
},
} }
auth_providers = [] auth_providers = []
for key, provider of auth_provider_all for key, provider of auth_provider_all

View file

@ -5,10 +5,12 @@
</div> </div>
<div class="page-content"> <div class="page-content">
<ul> <ul>
<% for auth_provider in @auth_providers: %> <% for key, provider of @auth_providers: %>
<li> <%- @T( auth_provider.name ) %> <li> <%- @T( provider.name ) %>
<% if !@user['accounts'] || !@user['accounts'][auth_provider.key]: %><a href="<%= auth_provider.url %>"><%- @T('Add') %></a> <% if !@user['accounts'] || !@user['accounts'][key]: %><a href="<%= provider.url %>">
<% else: %>"<%= @user['accounts'][auth_provider.key]['username'] %>" <a href="#" data-uid="<%= @user['accounts'][auth_provider.key]['uid'] %>" data-provider="<%= auth_provider.key %>" class="js-remove"><%- @T('remove') %></a> <%- @T('Add') %></a>
<% else: %>
"<%= @user['accounts'][key]['username'] %>" <a href="#" data-uid="<%= @user['accounts'][key]['uid'] %>" data-provider="<%= key %>" class="js-remove"><%- @T('remove') %></a>
<% end %> <% end %>
</li> </li>
<% end %> <% end %>

View file

@ -1,17 +1,47 @@
Rails.application.config.middleware.use OmniAuth::Builder do Rails.application.config.middleware.use OmniAuth::Builder do
# twitter database connect # twitter database connect
provider :twitter_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse', 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' } client_options: {
authorize_path: '/oauth/authorize',
site: 'https://api.twitter.com',
}
}
# facebook database connect # 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 # 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 # google database connect
provider :google_oauth2_database, 'not_change_will_be_set_by_databse', 'not_change_will_be_set_by_databse', 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: '' } 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 end

13
vendor/lib/github_database.rb vendored Normal file
View file

@ -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

14
vendor/lib/gitlab_database.rb vendored Normal file
View file

@ -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

14
vendor/lib/oauth2_database.rb vendored Normal file
View file

@ -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