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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
de5f2380
Commit
de5f2380
authored
Aug 17, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor `find_for_git_client` and its related methods.
parent
2f86860a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
20 deletions
+25
-20
lib/gitlab/auth.rb
lib/gitlab/auth.rb
+25
-20
No files found.
lib/gitlab/auth.rb
View file @
de5f2380
...
@@ -11,7 +11,7 @@ module Gitlab
...
@@ -11,7 +11,7 @@ module Gitlab
if
valid_ci_request?
(
login
,
password
,
project
)
if
valid_ci_request?
(
login
,
password
,
project
)
result
.
type
=
:ci
result
.
type
=
:ci
else
else
result
.
user
,
result
.
type
=
populate_result
(
login
,
password
)
result
=
populate_result
(
login
,
password
)
end
end
success
=
result
.
user
.
present?
||
[
:ci
,
:missing_personal_token
].
include?
(
result
.
type
)
success
=
result
.
user
.
present?
||
[
:ci
,
:missing_personal_token
].
include?
(
result
.
type
)
...
@@ -75,12 +75,34 @@ module Gitlab
...
@@ -75,12 +75,34 @@ module Gitlab
end
end
end
end
def
populate_result
(
login
,
password
)
result
=
user_with_password_for_git
(
login
,
password
)
||
oauth_access_token_check
(
login
,
password
)
||
personal_access_token_check
(
login
,
password
)
if
result
result
.
type
=
nil
unless
result
.
user
if
result
.
user
&&
result
.
user
.
two_factor_enabled?
&&
result
.
type
==
:gitlab_or_ldap
result
.
type
=
:missing_personal_token
end
end
result
||
Result
.
new
end
def
user_with_password_for_git
(
login
,
password
)
user
=
find_with_user_password
(
login
,
password
)
Result
.
new
(
user
,
:gitlab_or_ldap
)
if
user
end
def
oauth_access_token_check
(
login
,
password
)
def
oauth_access_token_check
(
login
,
password
)
if
login
==
"oauth2"
&&
password
.
present?
if
login
==
"oauth2"
&&
password
.
present?
token
=
Doorkeeper
::
AccessToken
.
by_token
(
password
)
token
=
Doorkeeper
::
AccessToken
.
by_token
(
password
)
if
token
&&
token
.
accessible?
if
token
&&
token
.
accessible?
user
=
User
.
find_by
(
id:
token
.
resource_owner_id
)
user
=
User
.
find_by
(
id:
token
.
resource_owner_id
)
return
user
,
:oauth
Result
.
new
(
user
,
:oauth
)
end
end
end
end
end
end
...
@@ -89,26 +111,9 @@ module Gitlab
...
@@ -89,26 +111,9 @@ module Gitlab
if
login
&&
password
if
login
&&
password
user
=
User
.
find_by_personal_access_token
(
password
)
user
=
User
.
find_by_personal_access_token
(
password
)
validation
=
User
.
by_login
(
login
)
validation
=
User
.
by_login
(
login
)
return
user
,
:personal_token
if
user
==
validation
Result
.
new
(
user
,
:personal_token
)
if
user
==
validation
end
end
end
end
def
user_with_password_for_git
(
login
,
password
)
user
=
find_with_user_password
(
login
,
password
)
return
user
,
:gitlab_or_ldap
if
user
end
def
populate_result
(
login
,
password
)
user
,
type
=
user_with_password_for_git
(
login
,
password
)
||
oauth_access_token_check
(
login
,
password
)
||
personal_access_token_check
(
login
,
password
)
if
user
&&
user
.
two_factor_enabled?
&&
type
==
:gitlab_or_ldap
user
=
nil
type
=
:missing_personal_token
end
[
user
,
type
]
end
end
end
end
end
end
end
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