Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CloWM Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computational Metagenomics
CloWM
CloWM Backend
Commits
5b1664d0
Commit
5b1664d0
authored
9 months ago
by
Daniel Göbel
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/5-change-query-parameter-for-return-path-in-login-route' into 'main'
Resolve "Change query parameter for return path in login route" Closes
#5
See merge request
!5
parents
70152f69
87ee49e8
No related branches found
No related tags found
1 merge request
!5
Resolve "Change query parameter for return path in login route"
Pipeline
#53123
passed
9 months ago
Stage: lint
Stage: test
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.pre-commit-config.yaml
+1
-1
1 addition, 1 deletion
.pre-commit-config.yaml
clowm/api/endpoints/login.py
+12
-11
12 additions, 11 deletions
clowm/api/endpoints/login.py
clowm/tests/api/test_login.py
+2
-2
2 additions, 2 deletions
clowm/tests/api/test_login.py
with
15 additions
and
14 deletions
.pre-commit-config.yaml
+
1
−
1
View file @
5b1664d0
...
...
@@ -32,7 +32,7 @@ repos:
files
:
clowm
args
:
[
--config=pyproject.toml
]
additional_dependencies
:
-
types-aiobotocore-lite[s3]
-
types-aiobotocore-lite[s3]
>=2.12.0,<2.13.0
-
sqlalchemy>=2.0.0,<2.1.0
-
pydantic>=2.6.0,<2.8.0
-
types-requests
...
...
This diff is collapsed.
Click to expand it.
clowm/api/endpoints/login.py
+
12
−
11
View file @
5b1664d0
...
...
@@ -22,7 +22,7 @@ from ..dependencies import DBSession, OIDCClientDep, RGWService
router
=
APIRouter
(
prefix
=
"
/auth
"
,
tags
=
[
"
Auth
"
])
tracer
=
trace
.
get_tracer_provider
().
get_tracer
(
__name__
)
RETURN
_PATH_KEY
=
"
return_path
"
NEXT
_PATH_KEY
=
"
NEXT
"
def
build_url
(
base_url
:
str
,
*
path
:
str
)
->
AnyHttpUrl
:
...
...
@@ -44,11 +44,12 @@ async def login(
provider
:
Annotated
[
OIDCClient
.
OIDCProvider
,
Query
(
description
=
"
The OIDC provider to use for login
"
)
]
=
OIDCClient
.
OIDCProvider
.
lifescience
,
return_path
:
Annotated
[
next_
:
Annotated
[
str
|
SkipJsonSchema
[
None
],
Query
(
alias
=
"
next
"
,
max_length
=
128
,
description
=
"
Will be appended to redirect response in the callback route as URL query parameter `
return
_path`
"
,
description
=
"
Will be appended to redirect response in the callback route as URL query parameter `
next
_path`
"
,
),
]
=
None
,
)
->
RedirectResponse
:
...
...
@@ -63,9 +64,9 @@ async def login(
The wrapper around the oidc client. Dependency Injection.
request : fastapi.requests.Request
Raw request object.
return_path
: str | None
next_
: str | None
Query parameter that gets stored in the session cookie.
Will be appended to RedirectResponse in the callback route as URL query parameter
'
return
_path
'
Will be appended to RedirectResponse in the callback route as URL query parameter
'
next
_path
'
Returns
-------
...
...
@@ -74,8 +75,8 @@ async def login(
"""
# Clear session to prevent an overflow
request
.
session
.
clear
()
if
return_path
:
request
.
session
[
RETURN
_PATH_KEY
]
=
return_path
if
next_
:
request
.
session
[
NEXT
_PATH_KEY
]
=
next_
redirect_uri
=
build_url
(
str
(
settings
.
ui_uri
),
settings
.
api_prefix
,
router
.
prefix
[
1
:],
"
callback
"
,
provider
.
name
)
return
await
oidc_client
.
authorize_redirect
(
request
,
redirect_uri
=
redirect_uri
,
provider
=
provider
)
...
...
@@ -142,10 +143,10 @@ async def login_callback(
"""
redirect_path
=
"
/
"
current_span
=
trace
.
get_current_span
()
return
_path
:
str
|
None
=
request
.
session
.
get
(
RETURN
_PATH_KEY
,
None
)
# get return path from session cookie
if
return
_path
is
not
None
:
current_span
.
set_attribute
(
"
return_path
"
,
return
_path
)
redirect_path
+=
f
"
?
return_path
=
{
urllib
.
parse
.
quote_plus
(
return
_path
)
}
"
next
_path
:
str
|
None
=
request
.
session
.
get
(
NEXT
_PATH_KEY
,
None
)
# get return path from session cookie
if
next
_path
is
not
None
:
current_span
.
set_attribute
(
"
next
"
,
next
_path
)
redirect_path
+=
f
"
?
next
=
{
urllib
.
parse
.
quote_plus
(
next
_path
)
}
"
try
:
user_info
=
await
oidc_client
.
verify_fetch_userinfo
(
request
=
request
,
provider
=
provider
)
lifescience_id
=
user_info
.
sub
if
isinstance
(
user_info
.
sub
,
str
)
else
user_info
.
sub
[
0
]
...
...
This diff is collapsed.
Click to expand it.
clowm/tests/api/test_login.py
+
2
−
2
View file @
5b1664d0
...
...
@@ -35,7 +35,7 @@ class TestLoginRoute:
"""
r
=
await
client
.
get
(
self
.
auth_path
+
"
/login
"
,
params
=
{
"
return_path
"
:
"
/dashboard
"
,
"
provider
"
:
"
lifescience
"
},
params
=
{
"
next
"
:
"
/dashboard
"
,
"
provider
"
:
"
lifescience
"
},
follow_redirects
=
False
,
)
assert
r
.
status_code
==
status
.
HTTP_302_FOUND
...
...
@@ -78,7 +78,7 @@ class TestLoginRoute:
assert
right_header
claim
=
decode_token
(
right_header
.
split
(
"
=
"
)[
1
])
assert
claim
[
"
sub
"
]
==
str
(
random_user
.
user
.
uid
)
assert
response
.
headers
[
"
location
"
].
startswith
(
f
"
/?
return_path
=
{
urllib
.
parse
.
quote_plus
(
'
/dashboard
'
)
}
"
)
assert
response
.
headers
[
"
location
"
].
startswith
(
f
"
/?
next
=
{
urllib
.
parse
.
quote_plus
(
'
/dashboard
'
)
}
"
)
@pytest.mark.asyncio
async
def
test_successful_login_with_existing_user_and_different_email
(
...
...
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