Implemented issue #1954 - Allow to automatically linking of existing user by initial login via third party authentication provider.

This commit is contained in:
Martin Edenhofer 2018-04-18 11:17:29 +02:00
parent c02393399a
commit c5e794d37b
4 changed files with 67 additions and 1 deletions

View file

@ -53,6 +53,12 @@ class Authorization < ApplicationModel
def self.create_from_hash(hash, user = nil)
if !user && Setting.get('auth_third_party_auto_link_at_inital_login')
if hash['info'] && hash['info']['email'].present?
user = User.find_by(email: hash['info']['email'].downcase)
end
end
if !user
user = User.create_from_hash!(hash)
end

View file

@ -386,7 +386,7 @@ returns
next if local_url.blank?
url = local_url
end
create(
create!(
login: hash['info']['nickname'] || hash['uid'],
firstname: hash['info']['name'],
email: hash['info']['email'],

View file

@ -0,0 +1,34 @@
class SettingThirdPartyLinkAccountAtLogin < ActiveRecord::Migration[5.1]
def up
# return if it's a new setup
return if !Setting.find_by(name: 'system_init_done')
Setting.create_if_not_exists(
title: 'Automatic account link on initial logon',
name: 'auth_third_party_auto_link_at_inital_login',
area: 'Security::ThirdPartyAuthentication',
description: 'Enables the automatic linking of an existing account on initial login via a third party application. If this is disabled, an existing user must first log into Zammad and then link his "Third Party" account to his Zammad account via Profile -> Linked Accounts.',
options: {
form: [
{
display: '',
null: true,
name: 'auth_third_party_auto_link_at_inital_login',
tag: 'boolean',
options: {
true => 'yes',
false => 'no',
},
},
],
},
preferences: {
permission: ['admin.security'],
prio: 10,
},
state: false,
frontend: false
)
end
end

View file

@ -954,6 +954,32 @@ Setting.create_if_not_exists(
},
frontend: false
)
Setting.create_if_not_exists(
title: 'Automatic account link on initial logon',
name: 'auth_third_party_auto_link_at_inital_login',
area: 'Security::ThirdPartyAuthentication',
description: 'Enables the automatic linking of an existing account on initial login via a third party application. If this is disabled, an existing user must first log into Zammad and then link his "Third Party" account to his Zammad account via Profile -> Linked Accounts.',
options: {
form: [
{
display: '',
null: true,
name: 'auth_third_party_auto_link_at_inital_login',
tag: 'boolean',
options: {
true => 'yes',
false => 'no',
},
},
],
},
preferences: {
permission: ['admin.security'],
prio: 10,
},
state: false,
frontend: false
)
Setting.create_if_not_exists(
title: 'Authentication via %s',
name: 'auth_twitter',