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
bb28339c
Commit
bb28339c
authored
Oct 7, 2020
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Got rid of requirement to use HTTPS for testing
parent
e14e7655
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.py
+8
-5
8 additions, 5 deletions
app.py
testapp/nginx.conf
+9
-7
9 additions, 7 deletions
testapp/nginx.conf
with
17 additions
and
12 deletions
app.py
+
8
−
5
View file @
bb28339c
import
os
from
functools
import
wraps
from
functools
import
wraps
import
secrets
,
json
import
secrets
,
json
import
urllib.parse
import
urllib.parse
...
@@ -9,9 +10,9 @@ from requests_oauthlib import OAuth2Session
...
@@ -9,9 +10,9 @@ from requests_oauthlib import OAuth2Session
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app
.
secret_key
=
b
'
my secret
'
app
.
secret_key
=
b
'
my secret
'
app
.
config
[
'
SESSION_COOKIE_NAME
'
]
=
'
oauth-session
'
app
.
config
[
'
SESSION_COOKIE_NAME
'
]
=
'
oauth-session
'
app
.
config
[
'
OAUTH2_AUTH_URL
'
]
=
'
http
s
://localhost:5001/oauth2/authorize
'
app
.
config
[
'
OAUTH2_AUTH_URL
'
]
=
'
http://localhost:5001/oauth2/authorize
'
app
.
config
[
'
OAUTH2_TOKEN_URL
'
]
=
'
http
s
://localhost:5001/oauth2/token
'
app
.
config
[
'
OAUTH2_TOKEN_URL
'
]
=
'
http://localhost:5001/oauth2/token
'
app
.
config
[
'
OAUTH2_USERINFO_URL
'
]
=
'
http
s
://localhost:5001/oauth2/userinfo
'
app
.
config
[
'
OAUTH2_USERINFO_URL
'
]
=
'
http://localhost:5001/oauth2/userinfo
'
@app.route
(
"
/auth
"
)
@app.route
(
"
/auth
"
)
def
auth
():
def
auth
():
...
@@ -37,7 +38,7 @@ def login():
...
@@ -37,7 +38,7 @@ def login():
@app.route
(
"
/callback
"
)
@app.route
(
"
/callback
"
)
def
callback
():
def
callback
():
client
=
get_oauth
(
state
=
session
.
pop
(
'
state
'
))
client
=
get_oauth
(
state
=
session
.
pop
(
'
state
'
))
token
=
client
.
fetch_token
(
app
.
config
[
'
OAUTH2_TOKEN_URL
'
],
client_secret
=
request
.
headers
[
'
X-CLIENT-SECRET
'
],
authorization_response
=
request
.
url
,
verify
=
False
)
token
=
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
()
userinfo
=
client
.
get
(
app
.
config
[
'
OAUTH2_USERINFO_URL
'
]).
json
()
session
[
'
user
'
]
=
userinfo
[
'
email
'
]
session
[
'
user
'
]
=
userinfo
[
'
email
'
]
return
redirect
(
session
.
pop
(
'
url
'
))
return
redirect
(
session
.
pop
(
'
url
'
))
...
@@ -75,4 +76,6 @@ a valid redirect_uri for the client_id.
...
@@ -75,4 +76,6 @@ a valid redirect_uri for the client_id.
return
resp
return
resp
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
,
host
=
'
localhost
'
,
port
=
5002
,
ssl_context
=
'
adhoc
'
)
# oauthlib enforces the OAuth2.0 requirement to use HTTPS, when this is not set
os
.
environ
[
'
OAUTHLIB_INSECURE_TRANSPORT
'
]
=
'
1
'
# Don't do that in production!
app
.
run
(
debug
=
True
,
host
=
'
localhost
'
,
port
=
5002
)
This diff is collapsed.
Click to expand it.
testapp/nginx.conf
+
9
−
7
View file @
bb28339c
...
@@ -18,9 +18,11 @@ http {
...
@@ -18,9 +18,11 @@ http {
tcp_nodelay
on
;
tcp_nodelay
on
;
keepalive_timeout
65
;
keepalive_timeout
65
;
types_hash_max_size
2048
;
types_hash_max_size
2048
;
ssl
on
;
# OAuth2.0 mandates HTTPS for all involved services. OAuthProxy will refuse
ssl_certificate
../devcert.crt
;
# to work over unencrypted connections.
ssl_certificate_key
../devcert.key
;
#ssl on;
#ssl_certificate mycert.crt;
#ssl_certificate_key myert.key;
server
{
server
{
#listen 50004;
#listen 50004;
#listen [::]:5004;
#listen [::]:5004;
...
@@ -39,17 +41,17 @@ http {
...
@@ -39,17 +41,17 @@ http {
}
}
location
/oauthproxy/
{
location
/oauthproxy/
{
proxy_set_header
X-REDIRECT-URI
"https://localhost:5004/oauthproxy/callback"
;
# The OAuth client credentials must match those configured on the OAuth server.
proxy_set_header
X-REDIRECT-URI
"http://localhost:5004/oauthproxy/callback"
;
proxy_set_header
X-CLIENT-ID
"test"
;
proxy_set_header
X-CLIENT-ID
"test"
;
proxy_set_header
X-CLIENT-SECRET
"testsecret"
;
proxy_set_header
X-CLIENT-SECRET
"testsecret"
;
proxy_set_header
X-SCOPE
"userinfo"
;
proxy_set_header
X-SCOPE
"userinfo"
;
proxy_ssl_verify
off
;
proxy_pass
http://localhost:5002/
;
proxy_pass
https://localhost:5002/
;
}
}
error_page
401
=
@error401
;
error_page
401
=
@error401
;
location
@error401
{
location
@error401
{
return
302
/oauthproxy/login?url=http
s
://
$http_host$request_uri
;
return
302
/oauthproxy/login?url=http://
$http_host$request_uri
;
}
}
}
}
...
...
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