Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pretix OIDC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Model registry
Monitor
Service Desk
Analyze
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
KIF
Pretix OIDC
Commits
6cb4c5a3
Commit
6cb4c5a3
authored
7 months ago
by
Felix Schäfer
Browse files
Options
Downloads
Patches
Plain Diff
Redirect to original URL after OIDC Auth
parent
e26d1c6a
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#257461
passed
7 months ago
Stage: linting
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pretix_oidc/auth.py
+30
-7
30 additions, 7 deletions
pretix_oidc/auth.py
with
30 additions
and
7 deletions
pretix_oidc/auth.py
+
30
−
7
View file @
6cb4c5a3
import
logging
import
logging
import
time
from
django.urls
import
reverse
from
django.urls
import
reverse
from
oic
import
rndstr
from
oic
import
rndstr
from
oic.oic
import
Client
from
oic.oic
import
Client
...
@@ -57,17 +58,24 @@ class OIDCAuthBackend(BaseAuthBackend):
...
@@ -57,17 +58,24 @@ class OIDCAuthBackend(BaseAuthBackend):
return
self
.
title
return
self
.
title
def
authentication_url
(
self
,
request
):
def
authentication_url
(
self
,
request
):
request
.
session
[
"
oidc_state
"
]
=
rndstr
()
oidc_state
=
rndstr
()
request
.
session
[
"
oidc_nonce
"
]
=
rndstr
()
oidc_nonce
=
rndstr
()
request
.
session
[
"
oidc_state
"
]
=
{
oidc_state
:
{
"
nonce
"
:
oidc_nonce
,
"
next
"
:
""
,
"
generated_on
"
:
int
(
time
.
time
()),
}
}
auth_req
=
self
.
client
.
construct_AuthorizationRequest
(
auth_req
=
self
.
client
.
construct_AuthorizationRequest
(
request_args
=
{
request_args
=
{
"
client_id
"
:
self
.
client
.
client_id
,
"
client_id
"
:
self
.
client
.
client_id
,
"
response_type
"
:
"
code
"
,
"
response_type
"
:
"
code
"
,
"
scope
"
:
self
.
scopes
,
"
scope
"
:
self
.
scopes
,
"
nonce
"
:
request
.
session
[
"
oidc_nonce
"
]
,
"
nonce
"
:
oidc_nonce
,
"
redirect_uri
"
:
self
.
redirect_uri
(
request
),
"
redirect_uri
"
:
self
.
redirect_uri
(
request
),
"
state
"
:
request
.
session
[
"
oidc_state
"
]
,
"
state
"
:
oidc_state
,
}
}
)
)
...
@@ -76,6 +84,9 @@ class OIDCAuthBackend(BaseAuthBackend):
...
@@ -76,6 +84,9 @@ class OIDCAuthBackend(BaseAuthBackend):
def
redirect_uri
(
self
,
request
):
def
redirect_uri
(
self
,
request
):
return
request
.
build_absolute_uri
(
reverse
(
"
plugins:pretix_oidc:oidc_callback
"
))
return
request
.
build_absolute_uri
(
reverse
(
"
plugins:pretix_oidc:oidc_callback
"
))
def
get_next_url
(
self
,
request
):
return
request
.
session
.
pop
(
"
oidc_next_url
"
,
None
)
def
process_callback
(
self
,
request
):
def
process_callback
(
self
,
request
):
auth_response
=
self
.
client
.
parse_response
(
auth_response
=
self
.
client
.
parse_response
(
AuthorizationResponse
,
AuthorizationResponse
,
...
@@ -83,12 +94,24 @@ class OIDCAuthBackend(BaseAuthBackend):
...
@@ -83,12 +94,24 @@ class OIDCAuthBackend(BaseAuthBackend):
sformat
=
"
urlencoded
"
,
sformat
=
"
urlencoded
"
,
)
)
# if auth_response is not AuthorizationResponse:
request
.
session
[
"
oidc_next_url
"
]
=
None
# raise Exception('Invalid authorization response')
oidc_state
=
request
.
session
.
pop
(
"
oidc_state
"
,
None
)
response_state
=
auth_response
.
get
(
"
state
"
,
None
)
if
not
oidc_state
or
not
response_state
:
return
[
None
,
None
]
if
response_state
not
in
oidc_state
:
return
[
None
,
None
]
if
auth_response
[
"
stat
e
"
]
!=
request
.
session
[
"
oidc_stat
e
"
]:
if
auth_response
[
"
nonc
e
"
]
!=
oidc_state
[
response_state
][
"
nonc
e
"
]:
return
[
None
,
None
]
return
[
None
,
None
]
if
oidc_state
[
response_state
][
"
generated_on
"
]
<
time
.
time
()
+
5
*
60
:
return
[
None
,
None
]
request
.
session
[
"
oidc_next_url
"
]
=
oidc_state
[
response_state
][
"
next
"
]
access_token_response
=
self
.
client
.
do_access_token_request
(
access_token_response
=
self
.
client
.
do_access_token_request
(
state
=
auth_response
[
"
state
"
],
state
=
auth_response
[
"
state
"
],
scope
=
self
.
scopes
,
scope
=
self
.
scopes
,
...
...
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