chandralegend commited on
Commit
4664e33
1 Parent(s): fd07f64

added authentication

Browse files
Files changed (1) hide show
  1. utils/login.py +33 -2
utils/login.py CHANGED
@@ -1,5 +1,10 @@
1
  import streamlit as st
2
  import os
 
 
 
 
 
3
 
4
 
5
  def initialize_login():
@@ -7,9 +12,9 @@ def initialize_login():
7
  st.columns(3)[1].image("assets/logo.png")
8
  username = st.text_input("Username")
9
  password = st.text_input("Password", type="password")
 
10
  if st.button("Login"):
11
- # TODO: replace with actual authorization check
12
- authorized = {"status": True, "Name": "John Doe", "username": "johndoe"}
13
  if authorized["status"]:
14
  st.session_state["login"] = authorized
15
  os.makedirs(
@@ -25,5 +30,31 @@ def initialize_login():
25
  st.sidebar.image("assets/logo.png", use_column_width=True)
26
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def get_login():
29
  return st.session_state.get("login", {"status": False})
 
1
  import streamlit as st
2
  import os
3
+ import requests
4
+ import os
5
+ import json
6
+
7
+ # Fetch the service account key JSON file contents
8
 
9
 
10
  def initialize_login():
 
12
  st.columns(3)[1].image("assets/logo.png")
13
  username = st.text_input("Username")
14
  password = st.text_input("Password", type="password")
15
+
16
  if st.button("Login"):
17
+ authorized = authenticate(username, password)
 
18
  if authorized["status"]:
19
  st.session_state["login"] = authorized
20
  os.makedirs(
 
30
  st.sidebar.image("assets/logo.png", use_column_width=True)
31
 
32
 
33
+ def authenticate(username, password):
34
+ FIREBASE_WEB_API_KEY = os.environ.get("FIREBASE_WEB_API_KEY")
35
+ payload = json.dumps(
36
+ {
37
+ "email": f"{username}@aieye.com",
38
+ "password": password,
39
+ "returnSecureToken": False,
40
+ }
41
+ )
42
+
43
+ rest_api_url = (
44
+ f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword"
45
+ )
46
+ r = requests.post(rest_api_url, params={"key": FIREBASE_WEB_API_KEY}, data=payload)
47
+ print(r.json())
48
+
49
+ if r.status_code == 200:
50
+ return {
51
+ "status": True,
52
+ "Name": " ".join(username.split("_")),
53
+ "username": username,
54
+ }
55
+ else:
56
+ return {"status": False}
57
+
58
+
59
  def get_login():
60
  return st.session_state.get("login", {"status": False})