Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
09ea27f1
Unverified
Commit
09ea27f1
authored
Aug 18, 2023
by
takatost
Committed by
GitHub
Aug 18, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: optimize service api authorization header invalid error (#910)
parent
db7156da
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
wraps.py
api/controllers/service_api/wraps.py
+6
-6
No files found.
api/controllers/service_api/wraps.py
View file @
09ea27f1
...
...
@@ -17,7 +17,7 @@ def validate_app_token(view=None):
def
decorated
(
*
args
,
**
kwargs
):
api_token
=
validate_and_get_api_token
(
'app'
)
app_model
=
db
.
session
.
query
(
App
)
.
get
(
api_token
.
app_id
)
app_model
=
db
.
session
.
query
(
App
)
.
filter
(
App
.
id
==
api_token
.
app_id
)
.
first
(
)
if
not
app_model
:
raise
NotFound
()
...
...
@@ -44,7 +44,7 @@ def validate_dataset_token(view=None):
def
decorated
(
*
args
,
**
kwargs
):
api_token
=
validate_and_get_api_token
(
'dataset'
)
dataset
=
db
.
session
.
query
(
Dataset
)
.
get
(
api_token
.
dataset_id
)
dataset
=
db
.
session
.
query
(
Dataset
)
.
filter
(
Dataset
.
id
==
api_token
.
dataset_id
)
.
first
(
)
if
not
dataset
:
raise
NotFound
()
...
...
@@ -64,14 +64,14 @@ def validate_and_get_api_token(scope=None):
Validate and get API token.
"""
auth_header
=
request
.
headers
.
get
(
'Authorization'
)
if
auth_header
is
None
:
raise
Unauthorized
()
if
auth_header
is
None
or
' '
not
in
auth_header
:
raise
Unauthorized
(
"Authorization header must be provided and start with 'Bearer'"
)
auth_scheme
,
auth_token
=
auth_header
.
split
(
None
,
1
)
auth_scheme
=
auth_scheme
.
lower
()
if
auth_scheme
!=
'bearer'
:
raise
Unauthorized
()
raise
Unauthorized
(
"Authorization scheme must be 'Bearer'"
)
api_token
=
db
.
session
.
query
(
ApiToken
)
.
filter
(
ApiToken
.
token
==
auth_token
,
...
...
@@ -79,7 +79,7 @@ def validate_and_get_api_token(scope=None):
)
.
first
()
if
not
api_token
:
raise
Unauthorized
()
raise
Unauthorized
(
"Access token is invalid"
)
api_token
.
last_used_at
=
datetime
.
utcnow
()
db
.
session
.
commit
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment