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
Léo-Paul Géneau
gitlab-ce
Commits
4e5a97d4
Commit
4e5a97d4
authored
Oct 21, 2017
by
Michael Kozono
Committed by
Francisco Lopez
Nov 17, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor with ActionDispatch::Request
parent
09b01c75
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
13 deletions
+11
-13
lib/gitlab/auth/request_authenticator.rb
lib/gitlab/auth/request_authenticator.rb
+11
-13
No files found.
lib/gitlab/auth/request_authenticator.rb
View file @
4e5a97d4
...
@@ -4,7 +4,7 @@ module Gitlab
...
@@ -4,7 +4,7 @@ module Gitlab
module
Auth
module
Auth
class
RequestAuthenticator
class
RequestAuthenticator
def
initialize
(
request
)
def
initialize
(
request
)
@request
=
request
@request
=
ensure_action_dispatch_request
(
request
)
end
end
def
user
def
user
...
@@ -21,21 +21,17 @@ module Gitlab
...
@@ -21,21 +21,17 @@ module Gitlab
@request
.
env
[
'warden'
]
&
.
authenticate
if
verified_request?
@request
.
env
[
'warden'
]
&
.
authenticate
if
verified_request?
end
end
# request may be Rack::Attack::Request which is just a Rack::Request, so
# we cannot use ActionDispatch::Request methods.
def
find_user_by_private_token
def
find_user_by_private_token
token
=
@request
.
params
[
'private_token'
].
presence
||
@request
.
env
[
'HTTP_PRIVATE_
TOKEN'
].
presence
token
=
@request
.
params
[
:private_token
].
presence
||
@request
.
headers
[
'PRIVATE-
TOKEN'
].
presence
return
unless
token
.
present?
return
unless
token
.
present?
User
.
find_by_authentication_token
(
token
)
||
User
.
find_by_personal_access_token
(
token
)
User
.
find_by_authentication_token
(
token
)
||
User
.
find_by_personal_access_token
(
token
)
end
end
# request may be Rack::Attack::Request which is just a Rack::Request, so
# we cannot use ActionDispatch::Request methods.
def
find_user_by_rss_token
def
find_user_by_rss_token
return
unless
@request
.
path
.
ends_with?
(
'atom'
)
||
@request
.
env
[
'HTTP_ACCEPT'
]
==
'application/atom+xml
'
return
unless
@request
.
path
.
ends_with?
(
'atom'
)
||
@request
.
format
==
'atom
'
token
=
@request
.
params
[
'rss_token'
].
presence
token
=
@request
.
params
[
:rss_token
].
presence
return
unless
token
.
present?
return
unless
token
.
present?
User
.
find_by_rss_token
(
token
)
User
.
find_by_rss_token
(
token
)
...
@@ -47,18 +43,20 @@ module Gitlab
...
@@ -47,18 +43,20 @@ module Gitlab
end
end
def
find_oauth_access_token
def
find_oauth_access_token
token
=
Doorkeeper
::
OAuth
::
Token
.
from_request
(
doorkeeper_
request
,
*
Doorkeeper
.
configuration
.
access_token_methods
)
token
=
Doorkeeper
::
OAuth
::
Token
.
from_request
(
@
request
,
*
Doorkeeper
.
configuration
.
access_token_methods
)
OauthAccessToken
.
by_token
(
token
)
if
token
OauthAccessToken
.
by_token
(
token
)
if
token
end
end
def
doorkeeper_request
ActionDispatch
::
Request
.
new
(
@request
.
env
)
end
# Check if the request is GET/HEAD, or if CSRF token is valid.
# Check if the request is GET/HEAD, or if CSRF token is valid.
def
verified_request?
def
verified_request?
Gitlab
::
RequestForgeryProtection
.
verified?
(
@request
.
env
)
Gitlab
::
RequestForgeryProtection
.
verified?
(
@request
.
env
)
end
end
def
ensure_action_dispatch_request
(
request
)
return
request
if
request
.
is_a?
(
ActionDispatch
::
Request
)
ActionDispatch
::
Request
.
new
(
request
.
env
)
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