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
Russ Garrett
uffd-nginxauth
Commits
151cf0b3
Commit
151cf0b3
authored
Oct 8, 2020
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Updated code and sample nginx config to uffd changes
parent
bb28339c
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
+12
-5
12 additions, 5 deletions
app.py
testapp/nginx.conf
+5
-5
5 additions, 5 deletions
testapp/nginx.conf
with
17 additions
and
10 deletions
app.py
+
12
−
5
View file @
151cf0b3
...
@@ -16,16 +16,19 @@ app.config['OAUTH2_USERINFO_URL'] = 'http://localhost:5001/oauth2/userinfo'
...
@@ -16,16 +16,19 @@ app.config['OAUTH2_USERINFO_URL'] = 'http://localhost:5001/oauth2/userinfo'
@app.route
(
"
/auth
"
)
@app.route
(
"
/auth
"
)
def
auth
():
def
auth
():
if
not
session
.
get
(
'
user
'
):
if
not
session
.
get
(
'
user
_id
'
):
abort
(
401
)
abort
(
401
)
resp
=
Response
(
'
Ok
'
,
200
)
resp
=
Response
(
'
Ok
'
,
200
)
resp
.
headers
[
'
REMOTE_USER
'
]
=
session
[
'
user
'
]
resp
.
headers
[
'
OAUTH-USER-ID
'
]
=
session
[
'
user_id
'
]
resp
.
headers
[
'
OAUTH-USER-NAME
'
]
=
session
[
'
user_name
'
]
resp
.
headers
[
'
OAUTH-USER-NICKNAME
'
]
=
session
[
'
user_nickname
'
]
resp
.
headers
[
'
OAUTH-USER-EMAIL
'
]
=
session
[
'
user_email
'
]
resp
.
headers
[
'
OAUTH-USER-GROUPS
'
]
=
'
,
'
.
join
(
session
[
'
user_groups
'
])
return
resp
return
resp
def
get_oauth
(
**
kwargs
):
def
get_oauth
(
**
kwargs
):
return
OAuth2Session
(
request
.
headers
[
'
X-CLIENT-ID
'
],
return
OAuth2Session
(
request
.
headers
[
'
X-CLIENT-ID
'
],
redirect_uri
=
request
.
headers
[
'
X-REDIRECT-URI
'
],
redirect_uri
=
request
.
headers
[
'
X-REDIRECT-URI
'
],
**
kwargs
)
scope
=
request
.
headers
[
'
X-SCOPE
'
],
**
kwargs
)
@app.route
(
"
/login
"
)
@app.route
(
"
/login
"
)
def
login
():
def
login
():
...
@@ -40,7 +43,11 @@ def callback():
...
@@ -40,7 +43,11 @@ 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
=
(
not
app
.
debug
))
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_id
'
]
=
userinfo
[
'
id
'
]
# (usually numeric) unique user id
session
[
'
user_name
'
]
=
userinfo
[
'
name
'
]
# display name
session
[
'
user_nickname
'
]
=
userinfo
[
'
nickname
'
]
# unique user name (for urls, @-handles, ...)
session
[
'
user_email
'
]
=
userinfo
[
'
email
'
]
session
[
'
user_groups
'
]
=
userinfo
[
'
groups
'
]
return
redirect
(
session
.
pop
(
'
url
'
))
return
redirect
(
session
.
pop
(
'
url
'
))
@app.route
(
"
/logout
"
)
@app.route
(
"
/logout
"
)
...
...
This diff is collapsed.
Click to expand it.
testapp/nginx.conf
+
5
−
5
View file @
151cf0b3
...
@@ -24,17 +24,19 @@ http {
...
@@ -24,17 +24,19 @@ http {
#ssl_certificate mycert.crt;
#ssl_certificate mycert.crt;
#ssl_certificate_key myert.key;
#ssl_certificate_key myert.key;
server
{
server
{
#listen 500
0
4;
#listen 5004;
#listen [::]:5004;
#listen [::]:5004;
listen
localhost
:
5004
;
listen
localhost
:
5004
;
location
/
{
location
/
{
# Unprotected resource
proxy_pass
http://localhost:5003
;
proxy_pass
http://localhost:5003
;
}
}
location
/test
{
location
/test
{
# Protected resource
auth_request
/oauthproxy/auth
;
auth_request
/oauthproxy/auth
;
auth_request_set
$auth_header
$upstream_http_
REMOTE_USER
;
auth_request_set
$auth_header
$upstream_http_
OAUTH_USER_NICKNAME
;
more_clear_input_headers
REMOTE-USER
;
# prevent spoofing
more_clear_input_headers
REMOTE-USER
;
# prevent spoofing
proxy_set_header
REMOTE-USER
$auth_header
;
proxy_set_header
REMOTE-USER
$auth_header
;
proxy_pass
http://localhost:5003
;
proxy_pass
http://localhost:5003
;
...
@@ -45,14 +47,12 @@ http {
...
@@ -45,14 +47,12 @@ http {
proxy_set_header
X-REDIRECT-URI
"http://localhost:5004/oauthproxy/callback"
;
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_pass
http://localhost:5002/
;
proxy_pass
http://localhost:5002/
;
}
}
error_page
401
=
@error401
;
error_page
401
=
@error401
;
location
@error401
{
location
@error401
{
return
302
/oauthproxy/login?url=
http
://
$http_host$request_uri
;
return
302
"
/oauthproxy/login?url=
$scheme
:
//
$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