-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62eb844
commit 748e53b
Showing
7 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import jwt | ||
import logging | ||
from functools import wraps | ||
from flask import request | ||
from flask_api import status | ||
from jwt.exceptions import PyJWTError, ExpiredSignatureError | ||
|
||
from resources.connections import JWT_SECRET | ||
|
||
|
||
def api_endpoint(): | ||
|
||
def wrapper(f): | ||
@wraps(f) | ||
def decorator_f(*args, **kwargs): | ||
try: | ||
if JWT_SECRET: | ||
auth_type, auth_token = request.headers.get( | ||
"Authorization", "" | ||
).split() | ||
jwt.decode( | ||
jwt=auth_token, | ||
key=JWT_SECRET, | ||
algorithms="HS256", | ||
issuer="noharm", | ||
) | ||
|
||
return f(*args, **kwargs) | ||
|
||
except ExpiredSignatureError: | ||
return { | ||
"status": "error", | ||
"message": "Token expirado", | ||
}, status.HTTP_401_UNAUTHORIZED | ||
|
||
except PyJWTError as e: | ||
logging.basicConfig() | ||
logger = logging.getLogger("noharm.getname") | ||
logger.exception(str(e)) | ||
|
||
return { | ||
"status": "error", | ||
"message": "Erro de autenticação. Consulte os logs para mais detalhes.", | ||
}, status.HTTP_401_UNAUTHORIZED | ||
|
||
except Exception as e: | ||
logging.basicConfig() | ||
logger = logging.getLogger("noharm.getname") | ||
logger.exception(str(e)) | ||
|
||
return { | ||
"status": "error", | ||
"message": "Erro inesperado. Consulte os logs para mais detalhes.", | ||
}, status.HTTP_500_INTERNAL_SERVER_ERROR | ||
|
||
return decorator_f | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
from resources.connections import JWT_SECRET | ||
|
||
|
||
def hello(): | ||
return "NoHarm - GetName 1.1\n\nServiço de nomes habilitado! Volte para a NoHarm e use o sistema normalmente ;)\n\n" | ||
version = "2.0" | ||
if JWT_SECRET: | ||
return f"NoHarm - GetName {version} (AUTH)\n\nServiço de nomes habilitado! Volte para a NoHarm e use o sistema normalmente ;)\n\n" | ||
|
||
return f"NoHarm - GetName {version}\n\nServiço de nomes habilitado! Volte para a NoHarm e use o sistema normalmente ;)\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ sqlalchemy-firebird | |
packaging | ||
uwsgi | ||
Werkzeug==2.3.7 | ||
PyJWT==2.9.0 |