Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
f8d54913
Commit
f8d54913
authored
Apr 22, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show error on failed OAuth account link
parent
f10c999b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
4 deletions
+46
-4
app/controllers/omniauth_callbacks_controller.rb
app/controllers/omniauth_callbacks_controller.rb
+6
-0
lib/gitlab/auth/o_auth/identity_linker.rb
lib/gitlab/auth/o_auth/identity_linker.rb
+16
-4
lib/gitlab/auth/omniauth_identity_linker_base.rb
lib/gitlab/auth/omniauth_identity_linker_base.rb
+4
-0
spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb
spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb
+20
-0
No files found.
app/controllers/omniauth_callbacks_controller.rb
View file @
f8d54913
...
@@ -84,6 +84,8 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
@@ -84,6 +84,8 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
if
identity_linker
.
created?
if
identity_linker
.
created?
redirect_identity_linked
redirect_identity_linked
elsif
identity_linker
.
error_message
.
present?
redirect_identity_link_failed
(
identity_linker
.
error_message
)
else
else
redirect_identity_exists
redirect_identity_exists
end
end
...
@@ -96,6 +98,10 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
...
@@ -96,6 +98,10 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
redirect_to
after_sign_in_path_for
(
current_user
)
redirect_to
after_sign_in_path_for
(
current_user
)
end
end
def
redirect_identity_link_failed
(
error_message
)
redirect_to
profile_account_path
,
notice:
"Authentication failed:
#{
error_message
}
"
end
def
redirect_identity_linked
def
redirect_identity_linked
redirect_to
profile_account_path
,
notice:
'Authentication method updated'
redirect_to
profile_account_path
,
notice:
'Authentication method updated'
end
end
...
...
lib/gitlab/auth/o_auth/identity_linker.rb
View file @
f8d54913
...
@@ -3,11 +3,23 @@ module Gitlab
...
@@ -3,11 +3,23 @@ module Gitlab
module
OAuth
module
OAuth
class
IdentityLinker
<
OmniauthIdentityLinkerBase
class
IdentityLinker
<
OmniauthIdentityLinkerBase
def
create_or_update
def
create_or_update
current_user
.
identities
if
identity
.
new_record?
.
with_extern_uid
(
oauth
[
'provider'
],
oauth
[
'uid'
])
@created
=
identity
.
save
.
first_or_create
(
extern_uid:
oauth
[
'uid'
])
end
end
def
error_message
identity
.
validate
@created
=
true
identity
.
errors
.
full_messages
.
join
(
', '
)
end
private
def
identity
@identity
||=
current_user
.
identities
.
with_extern_uid
(
oauth
[
'provider'
],
oauth
[
'uid'
])
.
first_or_initialize
(
extern_uid:
oauth
[
'uid'
])
end
end
end
end
end
end
...
...
lib/gitlab/auth/omniauth_identity_linker_base.rb
View file @
f8d54913
...
@@ -13,6 +13,10 @@ module Gitlab
...
@@ -13,6 +13,10 @@ module Gitlab
@created
@created
end
end
def
error_message
''
end
def
create_or_update
def
create_or_update
raise
NotImplementedError
raise
NotImplementedError
end
end
...
...
spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb
View file @
f8d54913
...
@@ -14,6 +14,26 @@ describe Gitlab::Auth::OAuth::IdentityLinker do
...
@@ -14,6 +14,26 @@ describe Gitlab::Auth::OAuth::IdentityLinker do
it
"doesn't create new identity"
do
it
"doesn't create new identity"
do
expect
{
subject
.
create_or_update
}.
not_to
change
{
Identity
.
count
}
expect
{
subject
.
create_or_update
}.
not_to
change
{
Identity
.
count
}
end
end
it
"#created? returns false"
do
subject
.
create_or_update
expect
(
subject
).
not_to
be_created
end
end
context
'identity already linked to different user'
do
let!
(
:identity
)
{
create
(
:identity
,
provider:
provider
,
extern_uid:
uid
)
}
it
"#created? returns false"
do
subject
.
create_or_update
expect
(
subject
).
not_to
be_created
end
it
'exposes error message'
do
expect
(
subject
.
error_message
).
to
eq
'Extern uid has already been taken'
end
end
end
context
'identity needs to be created'
do
context
'identity needs to be created'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment