Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
naifu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
naifu
Commits
ff28793e
Commit
ff28793e
authored
Oct 17, 2022
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve auth
parent
aefe7700
Pipeline
#17243
passed with stages
in 25 minutes and 3 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
+20
-20
docker-compose.yml
docker-compose.yml
+2
-2
main.py
main.py
+18
-18
No files found.
docker-compose.yml
View file @
ff28793e
...
...
@@ -8,8 +8,8 @@ services:
-
./models:/app/models
-
./main.py:/app/main.py:ro
-
./hydra_node:/app/hydra_node:ro
-
./static:/app/static:ro
#
- ./static:/app/static:ro
environment
:
# TOKEN_SERVER: https://api.moecube.com/accounts/authUser
TOKEN
:
mycard
WITH_STATIC
:
1
#
WITH_STATIC: 1
main.py
View file @
ff28793e
...
...
@@ -52,31 +52,31 @@ hostname = socket.gethostname()
sent_first_message
=
False
def
verify_token
(
req
:
Request
):
if
TOKEN
:
valid
=
"Authorization"
in
req
.
headers
and
req
.
headers
[
"Authorization"
]
==
"Bearer "
+
TOKEN
if
valid
:
return
True
if
not
TOKEN_SERVER
and
not
valid
:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Unauthorized"
)
if
not
TOKEN
and
not
TOKEN_SERVER
:
# no auth
return
True
if
"Authorization"
not
in
req
.
headers
:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Unauthorized"
)
token
=
req
.
headers
[
"Authorization"
]
if
token
.
startswith
(
"Bearer "
):
token
=
token
[
7
:]
if
TOKEN
and
token
==
TOKEN
:
return
True
if
TOKEN_SERVER
:
if
"Authorization"
not
in
req
.
headers
:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Unauthorized"
)
token
=
req
.
headers
[
"Authorization"
]
if
token
.
startswith
(
"Bearer "
):
token
=
token
[
7
:]
tokenAuthResult
=
requests
.
get
(
TOKEN_SERVER
,
headers
=
{
"Authorization"
:
"Bearer "
+
token
})
if
tokenAuthResult
.
status_code
>=
400
:
raise
HTTPException
(
status_code
=
tokenAuthResult
.
status_code
,
detail
=
"Unauthorized"
)
return
True
return
True
raise
HTTPException
(
status_code
=
401
,
detail
=
"Unauthorized"
)
#Initialize fastapi
app
=
FastAPI
()
...
...
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