Yarik commited on
Commit
324cb9f
·
1 Parent(s): dca572a

Add application file

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -49,7 +49,7 @@ password = os.getenv("XCHE_PASSWORD")
49
 
50
  fake_data_db = {
51
  api_key: {
52
- "api_key": api_key,
53
  "password": get_password_hash(password) # Pre-hashed password
54
  }
55
  }
@@ -69,14 +69,14 @@ def authenticate(fake_db, api_key: str, password: str):
69
 
70
  @app.post("/token")
71
  async def login(form_data: OAuth2PasswordRequestForm = Depends()):
72
- api_key = authenticate(fake_data_db, form_data.api_key, form_data.password)
73
  if not api_key:
74
  raise HTTPException(
75
  status_code=400,
76
  detail="Incorrect API KEY or Password",
77
  headers={"WWW-Authenticate": "Bearer"},
78
  )
79
- return {"access_token": api_key.api_key, "token_type": "bearer"}
80
 
81
  def check_api_token(token: str = Depends(oauth2_scheme)):
82
  api_key = get_api_key(fake_data_db, token)
 
49
 
50
  fake_data_db = {
51
  api_key: {
52
+ "username": api_key,
53
  "password": get_password_hash(password) # Pre-hashed password
54
  }
55
  }
 
69
 
70
  @app.post("/token")
71
  async def login(form_data: OAuth2PasswordRequestForm = Depends()):
72
+ api_key = authenticate(fake_data_db, form_data.username, form_data.password)
73
  if not api_key:
74
  raise HTTPException(
75
  status_code=400,
76
  detail="Incorrect API KEY or Password",
77
  headers={"WWW-Authenticate": "Bearer"},
78
  )
79
+ return {"access_token": api_key.username, "token_type": "bearer"}
80
 
81
  def check_api_token(token: str = Depends(oauth2_scheme)):
82
  api_key = get_api_key(fake_data_db, token)