BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
5fb44192
Commit
5fb44192
authored
Apr 15, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow personal access tokens to be used for API authentication.
parent
e8314ccc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
2 deletions
+14
-2
authentication.rb
lib/api/helpers/authentication.rb
+14
-2
No files found.
lib/api/helpers/authentication.rb
View file @
5fb44192
...
...
@@ -5,10 +5,22 @@ module API
PRIVATE_TOKEN_PARAM
=
:private_token
SUDO_HEADER
=
"HTTP_SUDO"
SUDO_PARAM
=
:sudo
PERSONAL_ACCESS_TOKEN_PARAM
=
:personal_access_token
def
current_user
def
find_user_by_private_token
private_token
=
(
params
[
PRIVATE_TOKEN_PARAM
]
||
env
[
PRIVATE_TOKEN_HEADER
]).
to_s
@current_user
||=
(
User
.
find_by
(
authentication_token:
private_token
)
||
doorkeeper_guard
)
User
.
find_by_authentication_token
(
private_token
)
end
def
find_user_by_personal_access_token
personal_access_token
=
PersonalAccessToken
.
find_by_token
(
params
[
PERSONAL_ACCESS_TOKEN_PARAM
])
if
personal_access_token
personal_access_token
.
user
end
end
def
current_user
@current_user
||=
(
find_user_by_private_token
||
find_user_by_personal_access_token
||
doorkeeper_guard
)
unless
@current_user
&&
Gitlab
::
UserAccess
.
allowed?
(
@current_user
)
return
nil
...
...
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