auth_helper: basic method to gen a permenant token

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2022-04-17 02:20:14 +03:00
parent a329ad3b10
commit 4617e5a7a2
Signed by: Hesham
GPG Key ID: 74876157D199B09E
3 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,5 @@
- [ ] Redesign database - [ ] Redesign database
- [ ] Define mergancy triggers (manual and automatic) - [ ] Define emrgancy triggers (manual and automatic)
- [ ] Expose temporary control in case of emergancy - [ ] Expose temporary control in case of emergancy
- Triggers - Triggers
- Acccess - Acccess

View File

@ -40,4 +40,9 @@ def authenticate_user(db: Session, username : str, password : str):
def valid_api_key(key = Security(api_key_header)): def valid_api_key(key = Security(api_key_header)):
if not __API_KEY == key: if not __API_KEY == key:
raise HTTPException(401, detail="invalid key") raise HTTPException(401, detail="invalid key")
return return
def create_iot_dev_token(data: dict):
to_encode = data.copy()
encoded_jwt = jwt.encode(to_encode, JWT_SECRET, algorithm=JWT_ALGO)
return encoded_jwt

View File

@ -1,5 +1,5 @@
from fastapi import Depends, FastAPI, HTTPException, status from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm, OAuth2AuthorizationCodeBearer
from fastapi.security.api_key import APIKey from fastapi.security.api_key import APIKey
from sqlalchemy.orm import Session from sqlalchemy.orm import Session