MCPcopy Create free account
hub / github.com/N4si/microservices-python-app / login

Function login

src/auth-service/server.py:17–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15
16@server.route('/login', methods=['POST'])
17def login():
18 auth_table_name = os.getenv('AUTH_TABLE')
19 auth = request.authorization
20 if not auth or not auth.username or not auth.password:
21 return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'}
22
23 conn = get_db_connection()
24 cur = conn.cursor()
25 query = f"SELECT email, password FROM {auth_table_name} WHERE email = %s"
26 res = cur.execute(query, (auth.username,))
27
28 if res is None:
29 user_row = cur.fetchone()
30 email = user_row[0]
31 password = user_row[1]
32
33 if auth.username != email or auth.password != password:
34 return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'}
35 else:
36 return CreateJWT(auth.username, os.environ['JWT_SECRET'], True)
37 else:
38 return 'Could not verify', 401, {'WWW-Authenticate': 'Basic realm="Login required!"'}
39
40def CreateJWT(username, secret, authz):
41 return jwt.encode(

Callers

nothing calls this directly

Calls 2

get_db_connectionFunction · 0.85
CreateJWTFunction · 0.85

Tested by

no test coverage detected