Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd-nginxauth
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
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uffd
uffd-nginxauth
Commits
edb31385
Commit
edb31385
authored
Sep 19, 2021
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Minor code cleanup
parent
7c86f004
Branches
feature/conference-query-set
No related tags found
1 merge request
!2
Minor code cleanup
Pipeline
#7772
passed
Sep 19, 2021
Stage: test
Changes
2
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.py
+14
-15
14 additions, 15 deletions
app.py
pytest.ini
+5
-0
5 additions, 0 deletions
pytest.ini
with
19 additions
and
15 deletions
app.py
+
14
−
15
View file @
edb31385
...
...
@@ -14,9 +14,10 @@ def create_app(test_config=None):
else
:
app
.
config
.
from_mapping
(
test_config
)
# oauthlib enforces the OAuth2.0 requirement to use HTTPS, when this is not set
os
.
environ
[
'
OAUTHLIB_INSECURE_TRANSPORT
'
]
=
'
1
'
# That behaviour sucks, so disable it
if
app
.
debug
:
os
.
environ
[
'
OAUTHLIB_INSECURE_TRANSPORT
'
]
=
'
1
'
@app.route
(
"
/auth
"
)
@app.route
(
'
/auth
'
)
def
auth
():
if
not
session
.
get
(
'
user_id
'
):
abort
(
401
)
...
...
@@ -33,7 +34,7 @@ def create_app(test_config=None):
return
OAuth2Session
(
request
.
headers
[
'
X-CLIENT-ID
'
],
redirect_uri
=
request
.
headers
[
'
X-REDIRECT-URI
'
],
**
kwargs
)
@app.route
(
"
/login
"
)
@app.route
(
'
/login
'
)
def
login
():
client
=
get_oauth
()
url
,
state
=
client
.
authorization_url
(
app
.
config
[
'
OAUTH2_AUTH_URL
'
])
...
...
@@ -45,10 +46,10 @@ def create_app(test_config=None):
session
[
'
url
'
]
=
request
.
values
.
get
(
'
url
'
,
'
/
'
)
return
redirect
(
url
)
@app.route
(
"
/callback
"
)
@app.route
(
'
/callback
'
)
def
callback
():
client
=
get_oauth
(
state
=
session
.
pop
(
'
state
'
))
token
=
client
.
fetch_token
(
app
.
config
[
'
OAUTH2_TOKEN_URL
'
],
client
.
fetch_token
(
app
.
config
[
'
OAUTH2_TOKEN_URL
'
],
client_secret
=
request
.
headers
[
'
X-CLIENT-SECRET
'
],
authorization_response
=
request
.
url
,
verify
=
(
not
app
.
debug
))
userinfo
=
client
.
get
(
app
.
config
[
'
OAUTH2_USERINFO_URL
'
]).
json
()
...
...
@@ -60,27 +61,27 @@ def create_app(test_config=None):
session
[
'
user_groups
'
]
=
userinfo
[
'
groups
'
]
return
redirect
(
session
.
pop
(
'
url
'
))
@app.route
(
"
/logout
"
)
@app.route
(
'
/logout
'
)
def
logout
():
session
.
clear
()
resp
=
Response
(
'
Ok
'
,
200
)
if
request
.
values
.
get
(
'
redirect_url
'
):
resp
=
redirect
(
request
.
values
.
get
(
'
redirect_url
'
))
if
request
.
values
.
get
(
'
clear_cookies
'
):
for
key
,
data
in
request
.
cookies
.
items
():
for
key
,
_
in
request
.
cookies
.
items
():
resp
.
delete_cookie
(
key
)
return
resp
@app.route
(
"
/status
"
)
@app.route
(
'
/status
'
)
def
status
():
resp
=
Response
(
'''
Proxy Configuration Status
resp
=
Response
(
f
'''
Proxy Configuration Status
For this proxy service to work properly, the OAuth client crendentials must
be injected in by the webserver as HTTP-headers:
X-CLIENT-ID:
%s
X-CLIENT-SECRET:
%s
X-REDIRECT-URI:
%s
X-CLIENT-ID:
{
request
.
headers
.
get
(
'
X-CLIENT-ID
'
,
'
(unset)
'
)
}
X-CLIENT-SECRET:
{
'
(set)
'
if
request
.
headers
.
get
(
'
X-CLIENT-SECRET
'
)
else
'
(unset)
'
}
X-REDIRECT-URI:
{
request
.
headers
.
get
(
'
X-REDIRECT-URI
'
,
'
(unset)
'
)
}
If you accessed this ressource with the URL
...
...
@@ -92,9 +93,7 @@ then the redirect URI must be set to:
This exact redirect URI must also be registered with the OAuth server as
a valid redirect_uri for the client_id.
'''
%
(
request
.
headers
.
get
(
'
X-CLIENT-ID
'
,
'
(unset)
'
),
'
(set)
'
if
request
.
headers
.
get
(
'
X-CLIENT-SECRET
'
)
else
'
(unset)
'
,
request
.
headers
.
get
(
'
X-REDIRECT-URI
'
,
'
(unset)
'
)))
'''
)
resp
.
mimetype
=
'
text/plain; charset=utf-8
'
return
resp
...
...
This diff is collapsed.
Click to expand it.
pytest.ini
0 → 100644
+
5
−
0
View file @
edb31385
[pytest]
filterwarnings
=
# DeprecationWarning from dependencies that we use
ignore:Using
or
importing
the
ABCs
from
'collections'
instead
of
from
'collections.abc'
is
deprecated
since
Python
3.3,
and
in
3.10
it
will
stop
working:DeprecationWarning
ignore:Please
switch
to
the
public
method
populate_token_attributes.:DeprecationWarning
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