-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
8 changed files
with
1,424 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM python:3.10.10 | ||
|
||
WORKDIR /app | ||
|
||
RUN pip install --upgrade pip | ||
|
||
COPY requirements.txt requirements.txt | ||
|
||
RUN pip install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
EXPOSE 8080 | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
|
||
CMD ["uvicorn", "--host", "0.0.0.0", "--port", "8080", "main:app"] |
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,29 @@ | ||
# authorization (verify the route) | ||
from fastapi import Request, HTTPException | ||
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials | ||
from .jwt_handler import decodeJWT | ||
|
||
|
||
class jwtBearer(HTTPBearer): | ||
def __init__(self, auto_Error : bool = True): | ||
super(jwtBearer, self).__init__(auto_error=auto_Error) | ||
|
||
async def __call__(self, request : Request): | ||
credentials : HTTPAuthorizationCredentials = await super(jwtBearer, | ||
self).__call__(request) | ||
if credentials: | ||
if not credentials.scheme == "Bearer": | ||
raise HTTPException(status_code = 403, details="token is no longer available :(((") | ||
return credentials.credentials | ||
#for any reason why everything is not according to plan we still will make fun of their's credentials | ||
else: | ||
raise HTTPException(status_code = 403, details="token is no longer available :(((") | ||
|
||
def verify_jwt(self, jwtoken : str): | ||
isTokenValid : bool = False # a false flag | ||
payload = decodeJWT(jwtoken) | ||
if payload: | ||
isTokenValid = True | ||
|
||
|
||
return isTokenValid |
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,35 @@ | ||
#this file for encoding and decoding and returning jwts | ||
import hashlib | ||
import jwt | ||
import time | ||
from decouple import config | ||
from typing import Dict | ||
|
||
JWT_SECRET = config("secret") | ||
JWT_ALGORITHM = config("algorithm") | ||
|
||
#deez generated tokens (jwts) | ||
def token_response(token: str): | ||
return{ | ||
"access token": token | ||
} | ||
|
||
def signJWT(userID : str): | ||
payload = { | ||
"userID" : userID, | ||
"expiry" : time.time() + 600 | ||
} | ||
token = jwt.encode(payload,JWT_SECRET, algorithm=JWT_ALGORITHM) | ||
return token_response(token) | ||
|
||
|
||
def decodeJWT(token:str): | ||
try: | ||
decode_token = jwt.decode(token, JWT_SECRET, algorithm=JWT_ALGORITHM) | ||
return decode_token if decode_token['expires'] >= time.time()else None | ||
except: | ||
return {} | ||
|
||
|
||
|
||
|
Oops, something went wrong.