Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
thies
uffd2
Commits
faa8a699
Commit
faa8a699
authored
3 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Remove deprecated API_CLIENTS option and Bearer API authentication
See
917f9ecd
parent
d6f63c8d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_api.py
+0
-24
0 additions, 24 deletions
tests/test_api.py
uffd/api/views.py
+1
-13
1 addition, 13 deletions
uffd/api/views.py
uffd/default_config.cfg
+0
-5
0 additions, 5 deletions
uffd/default_config.cfg
with
1 addition
and
42 deletions
tests/test_api.py
+
0
−
24
View file @
faa8a699
...
@@ -10,10 +10,6 @@ def basic_auth(username, password):
...
@@ -10,10 +10,6 @@ def basic_auth(username, password):
class
TestAPIAuth
(
UffdTestCase
):
class
TestAPIAuth
(
UffdTestCase
):
def
setUpApp
(
self
):
def
setUpApp
(
self
):
self
.
app
.
config
[
'
API_CLIENTS
'
]
=
{
'
testtoken1
'
:
{
'
scopes
'
:
[
'
testscope
'
]},
'
testtoken2
'
:
{},
}
self
.
app
.
config
[
'
API_CLIENTS_2
'
]
=
{
self
.
app
.
config
[
'
API_CLIENTS_2
'
]
=
{
'
test1
'
:
{
'
client_secret
'
:
'
testsecret1
'
,
'
scopes
'
:
[
'
getusers
'
,
'
testscope
'
]},
'
test1
'
:
{
'
client_secret
'
:
'
testsecret1
'
,
'
scopes
'
:
[
'
getusers
'
,
'
testscope
'
]},
'
test2
'
:
{
'
client_secret
'
:
'
testsecret2
'
},
'
test2
'
:
{
'
client_secret
'
:
'
testsecret2
'
},
...
@@ -56,26 +52,6 @@ class TestAPIAuth(UffdTestCase):
...
@@ -56,26 +52,6 @@ class TestAPIAuth(UffdTestCase):
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint3
'
),
headers
=
[
basic_auth
(
'
test2
'
,
'
testsecret2
'
)],
follow_redirects
=
True
)
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint3
'
),
headers
=
[
basic_auth
(
'
test2
'
,
'
testsecret2
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
403
)
self
.
assertEqual
(
r
.
status_code
,
403
)
def
test_bearer
(
self
):
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint1
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken1
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
200
)
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint2
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken1
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
200
)
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint3
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken1
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
200
)
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint1
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken2
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
200
)
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint2
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken2
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
200
)
def
test_bearer_invalid_credentials
(
self
):
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint1
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken-none
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
401
)
def
test_bearer_missing_scope
(
self
):
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint3
'
),
headers
=
[(
'
Authorization
'
,
'
Bearer testtoken2
'
)],
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
401
)
def
test_no_auth
(
self
):
def
test_no_auth
(
self
):
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint1
'
),
follow_redirects
=
True
)
r
=
self
.
client
.
get
(
path
=
url_for
(
'
testendpoint1
'
),
follow_redirects
=
True
)
self
.
assertEqual
(
r
.
status_code
,
401
)
self
.
assertEqual
(
r
.
status_code
,
401
)
This diff is collapsed.
Click to expand it.
uffd/api/views.py
+
1
−
13
View file @
faa8a699
...
@@ -22,20 +22,8 @@ def apikey_required(scope=None):
...
@@ -22,20 +22,8 @@ def apikey_required(scope=None):
return
'
Unauthorized
'
,
401
,
{
'
WWW-Authenticate
'
:
[
'
Basic realm=
"
api
"'
]}
return
'
Unauthorized
'
,
401
,
{
'
WWW-Authenticate
'
:
[
'
Basic realm=
"
api
"'
]}
if
scope
is
not
None
and
scope
not
in
client
.
get
(
'
scopes
'
,
[]):
if
scope
is
not
None
and
scope
not
in
client
.
get
(
'
scopes
'
,
[]):
return
'
Forbidden
'
,
403
return
'
Forbidden
'
,
403
# To be removed in uffd v2
elif
'
Authorization
'
in
request
.
headers
and
request
.
headers
[
'
Authorization
'
].
startswith
(
'
Bearer
'
):
token
=
request
.
headers
[
'
Authorization
'
][
7
:].
strip
()
client
=
None
for
client_token
,
data
in
current_app
.
config
[
'
API_CLIENTS
'
].
items
():
if
secrets
.
compare_digest
(
client_token
,
token
):
client
=
data
if
client
is
None
:
return
'
Unauthorized
'
,
401
,
{
'
WWW-Authenticate
'
:
'
Bearer error=
"
invalid_token
"'
}
client_scopes
=
[
'
getusers
'
]
+
client
.
get
(
'
scopes
'
,
[])
if
scope
is
not
None
and
scope
not
in
client_scopes
:
return
'
Unauthorized
'
,
401
,
{
'
WWW-Authenticate
'
:
'
Bearer error=
"
insufficient_scope
"
,scope=
"
%s
"'
%
scope
}
else
:
else
:
return
'
Unauthorized
'
,
401
,
{
'
WWW-Authenticate
'
:
[
'
Bearer
'
,
'
Basic realm=
"
api
"'
]}
return
'
Unauthorized
'
,
401
,
{
'
WWW-Authenticate
'
:
[
'
Basic realm=
"
api
"'
]}
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
decorator
return
decorator
return
wrapper
return
wrapper
...
...
This diff is collapsed.
Click to expand it.
uffd/default_config.cfg
+
0
−
5
View file @
faa8a699
...
@@ -60,11 +60,6 @@ OAUTH2_CLIENTS={
...
@@ -60,11 +60,6 @@ OAUTH2_CLIENTS={
# Set 'login_message' (or suffixed with a language code like 'login_message_de') to display a custom message on the login form.
# Set 'login_message' (or suffixed with a language code like 'login_message_de') to display a custom message on the login form.
}
}
# Deprecated, will be removed in uffd v2
API_CLIENTS
=
{
#'token': {'scopes': ['checkpassword']}
}
API_CLIENTS_2
=
{
API_CLIENTS_2
=
{
#'test_client_id' : {'client_secret': 'random_secret', 'scopes': ['users', 'checkpassword']},
#'test_client_id' : {'client_secret': 'random_secret', 'scopes': ['users', 'checkpassword']},
# Scopes:
# 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