Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Portal API Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kontr 2.0
Portal API Backend
Commits
fb5ae3ff
There was an error fetching the commit references. Please try again later.
Commit
fb5ae3ff
authored
7 years ago
by
Barbora Kompišová
Browse files
Options
Downloads
Patches
Plain Diff
oauth base login
parent
b7db3987
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
portal/rest/auth/gitlab.py
+5
-9
5 additions, 9 deletions
portal/rest/auth/gitlab.py
portal/rest/auth/login.py
+2
-2
2 additions, 2 deletions
portal/rest/auth/login.py
portal/service/auth.py
+8
-2
8 additions, 2 deletions
portal/service/auth.py
with
15 additions
and
13 deletions
portal/rest/auth/gitlab.py
+
5
−
9
View file @
fb5ae3ff
import
logging
from
flask
import
Blueprint
,
Flask
,
Config
,
url_for
,
request
,
redirect
,
session
,
jsonify
,
\
make_response
from
flask
import
Blueprint
,
url_for
,
request
,
redirect
,
session
,
make_response
from
flask_oauthlib.client
import
OAuth
,
OAuthRemoteApp
from
portal
import
oauth
from
portal.database.models
import
User
from
portal.service
import
service
from
portal.service.service
import
find_user
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -47,10 +47,6 @@ def oauth_login():
return
gitlab
.
authorize
(
callback
=
callback
)
def
user_oauth_login
(
user
):
pass
def
user_oauth_register
(
user_info
):
new_user
=
User
(
uco
=
None
,
...
...
@@ -64,11 +60,11 @@ def user_oauth_register(user_info):
def
user_login
(
user_info
):
user
=
User
.
query
.
find_
by
(
user
name
=
user_info
[
'
user
_
name
'
])
user
=
find_user
(
user_info
[
'
username
'
])
if
not
user
:
return
user_oauth_register
(
user_info
)
user_oauth_register
(
user_info
)
resp
=
make_response
(
redirect
(
oauth
.
app
.
config
.
get
(
'
FRONTEND_URL
'
)))
resp
.
set_cookie
(
'
user
_
name
'
,
user
.
username
)
resp
.
set_cookie
(
'
username
'
,
user
.
username
)
return
resp
...
...
This diff is collapsed.
Click to expand it.
portal/rest/auth/login.py
+
2
−
2
View file @
fb5ae3ff
...
...
@@ -30,8 +30,8 @@ class Login(Resource):
raise
PortalAPIError
(
400
,
message
=
"
Missing login type.
"
)
if
data
[
'
type
'
]
==
'
user
'
:
username
=
data
.
get
(
'
username
'
)
password
=
data
.
get
(
'
password
'
)
username
=
data
.
get
(
'
username
'
,
None
)
password
=
data
.
get
(
'
password
'
,
None
)
gitlab_access_token
=
data
.
get
(
'
gitlab_access_token
'
,
None
)
client
=
login_user
(
gitlab_access_token
,
password
,
username
)
...
...
This diff is collapsed.
Click to expand it.
portal/service/auth.py
+
8
−
2
View file @
fb5ae3ff
from
portal.service.errors
import
IncorrectPasswordError
,
UnauthorizedError
from
portal.service.errors
import
IncorrectPasswordError
,
UnauthorizedError
,
PortalAPIError
from
portal.service.service
import
find_user
,
find_component
...
...
@@ -20,11 +20,17 @@ def auth_gitlab_access_token(username, gitlab_access_token):
Verify that token is for user
Args:
gitlab_access_token:
username: username of the user attempting to log in
gitlab_access_token: access token string from gitlab
Returns: the authenticated user
"""
if
gitlab_access_token
is
None
:
raise
PortalAPIError
(
400
,
'
No gitlab access token found.
'
)
# TODO: validate gitlab token
user
=
find_user
(
username
)
return
user
def
auth_username_password
(
username
,
password
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment