Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
a2fbcd94
Commit
a2fbcd94
authored
2 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add task authentication
parent
4095908d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex/ponos/authentication.py
+35
-1
35 additions, 1 deletion
arkindex/ponos/authentication.py
arkindex/project/settings.py
+1
-0
1 addition, 0 deletions
arkindex/project/settings.py
arkindex/project/tests/openapi/test_schema.py
+1
-0
1 addition, 0 deletions
arkindex/project/tests/openapi/test_schema.py
with
37 additions
and
1 deletion
arkindex/ponos/authentication.py
+
35
−
1
View file @
a2fbcd94
from
drf_spectacular.authentication
import
TokenScheme
from
drf_spectacular.contrib.rest_framework_simplejwt
import
SimpleJWTScheme
from
rest_framework.authentication
import
TokenAuthentication
from
rest_framework.exceptions
import
AuthenticationFailed
from
arkindex.ponos.models
import
Agent
from
arkindex.ponos.models
import
Agent
,
Task
from
rest_framework_simplejwt.authentication
import
JWTAuthentication
from
rest_framework_simplejwt.exceptions
import
InvalidToken
from
rest_framework_simplejwt.settings
import
api_settings
...
...
@@ -68,3 +70,35 @@ class AgentAuthenticationExtension(SimpleJWTScheme):
target_class
=
"
arkindex.ponos.authentication.AgentAuthentication
"
name
=
"
agentAuth
"
class
TaskAuthentication
(
TokenAuthentication
):
keyword
=
'
Ponos
'
model
=
Task
def
authenticate_credentials
(
self
,
key
):
try
:
task
=
Task
.
objects
.
select_related
(
'
workflow__process__creator
'
).
get
(
token
=
key
)
except
Task
.
DoesNotExist
:
# Same error message as the standard TokenAuthentication
raise
AuthenticationFailed
(
'
Invalid token.
'
)
if
not
task
.
workflow
.
process
:
raise
AuthenticationFailed
(
'
Task has no process.
'
)
user
=
task
.
workflow
.
process
.
creator
if
not
user
or
not
user
.
is_active
:
# Same error message as the standard TokenAuthentication
raise
AuthenticationFailed
(
'
User inactive or deleted.
'
)
return
(
user
,
task
)
class
TaskAuthenticationExtension
(
TokenScheme
):
target_class
=
"
arkindex.ponos.authentication.TaskAuthentication
"
name
=
"
taskAuth
"
# The TokenScheme has a priority of -1 and matches both TokenAuthentication and its subclasses;
# we set the priority to a higher number to make this extension match first, and disable
# subclass matching so that this only applies to the TaskAuthentication.
priority
=
0
match_subclasses
=
False
This diff is collapsed.
Click to expand it.
arkindex/project/settings.py
+
1
−
0
View file @
a2fbcd94
...
...
@@ -202,6 +202,7 @@ REST_FRAMEWORK = {
'
rest_framework.authentication.SessionAuthentication
'
,
'
rest_framework.authentication.TokenAuthentication
'
,
'
arkindex.ponos.authentication.AgentAuthentication
'
,
'
arkindex.ponos.authentication.TaskAuthentication
'
,
),
'
DEFAULT_PAGINATION_CLASS
'
:
'
arkindex.project.pagination.PageNumberPagination
'
,
'
DEFAULT_SCHEMA_CLASS
'
:
'
arkindex.project.openapi.AutoSchema
'
,
...
...
This diff is collapsed.
Click to expand it.
arkindex/project/tests/openapi/test_schema.py
+
1
−
0
View file @
a2fbcd94
...
...
@@ -56,6 +56,7 @@ class TestAutoSchema(TestCase):
{
'
cookieAuth
'
:
[]},
{
'
tokenAuth
'
:
[]},
{
'
agentAuth
'
:
[]},
{
'
taskAuth
'
:
[]},
# Allows no authentication too
{},
],
...
...
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