Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
295 implement token based auth (#296)
* Support user login. (#294) * Support user login. (#294) * Support user login. (#294) * 291 support token based auth (#293) * 1. Added a new file "auth.py" to the "app/auth" directory, which contains a function "auth_required" that is used as a decorator for route functions that require authentication. This function checks for the presence of credentials in the request's authorization header and verifies them against the user model in the database. If the credentials are valid, the user object is added to the Flask's "g" object and the route function is called. If the credentials are missing or invalid, a 401 Unauthorized response is returned. 2. Updated the "notebook.py" file in the "app/routes" directory to import the "auth_required" function from the "auth.py" file. This function is then used as a decorator for the "get_all_notebooks" route function, which requires authentication. This ensures that only authenticated users can access the route. 3. Added the "@auth_required" decorator above the "get_all_notebooks" route function in the "notebook.py" file. This decorator ensures that the route function is only called if the user is authenticated. If the user is not authenticated, a 401 Unauthorized response is returned. 4. Added a new test case to the "test_notebook_route.py" file to test the authentication functionality of the "get_all_notebooks" route. This test case sends a GET request to the route without providing any credentials and asserts that the response status code is 401 Unauthorized. 5. Updated the commit message to include the changes made in the previous commits. * 291 support token based auth (#293) * 1. Added a new file "auth.py" to the "app/auth" directory, which contains a function "auth_required" that is used as a decorator for route functions that require authentication. This function checks for the presence of credentials in the request's authorization header and verifies them against the user model in the database. If the credentials are valid, the user object is added to the Flask's "g" object and the route function is called. If the credentials are missing or invalid, a 401 Unauthorized response is returned. 2. Updated the "notebook.py" file in the "app/routes" directory to import the "auth_required" function from the "auth.py" file. This function is then used as a decorator for the "get_all_notebooks" route function, which requires authentication. This ensures that only authenticated users can access the route. 3. Added the "@auth_required" decorator above the "get_all_notebooks" route function in the "notebook.py" file. This decorator ensures that the route function is only called if the user is authenticated. If the user is not authenticated, a 401 Unauthorized response is returned. 4. Added a new test case to the "test_notebook_route.py" file to test the authentication functionality of the "get_all_notebooks" route. This test case sends a GET request to the route without providing any credentials and asserts that the response status code is 401 Unauthorized. 5. Updated the commit message to include the changes made in the previous commits. * 291 support token based auth (#293) * 1. Added a new file "auth.py" to the "app/auth" directory, which contains a function "auth_required" that is used as a decorator for route functions that require authentication. This function checks for the presence of credentials in the request's authorization header and verifies them against the user model in the database. If the credentials are valid, the user object is added to the Flask's "g" object and the route function is called. If the credentials are missing or invalid, a 401 Unauthorized response is returned. 2. Updated the "notebook.py" file in the "app/routes" directory to import the "auth_required" function from the "auth.py" file. This function is then used as a decorator for the "get_all_notebooks" route function, which requires authentication. This ensures that only authenticated users can access the route. 3. Added the "@auth_required" decorator above the "get_all_notebooks" route function in the "notebook.py" file. This decorator ensures that the route function is only called if the user is authenticated. If the user is not authenticated, a 401 Unauthorized response is returned. 4. Added a new test case to the "test_notebook_route.py" file to test the authentication functionality of the "get_all_notebooks" route. This test case sends a GET request to the route without providing any credentials and asserts that the response status code is 401 Unauthorized. 5. Updated the commit message to include the changes made in the previous commits. * 291 support token based auth (#293) * 1. Added a new file "auth.py" to the "app/auth" directory, which contains a function "auth_required" that is used as a decorator for route functions that require authentication. This function checks for the presence of credentials in the request's authorization header and verifies them against the user model in the database. If the credentials are valid, the user object is added to the Flask's "g" object and the route function is called. If the credentials are missing or invalid, a 401 Unauthorized response is returned. 2. Updated the "notebook.py" file in the "app/routes" directory to import the "auth_required" function from the "auth.py" file. This function is then used as a decorator for the "get_all_notebooks" route function, which requires authentication. This ensures that only authenticated users can access the route. 3. Added the "@auth_required" decorator above the "get_all_notebooks" route function in the "notebook.py" file. This decorator ensures that the route function is only called if the user is authenticated. If the user is not authenticated, a 401 Unauthorized response is returned. 4. Added a new test case to the "test_notebook_route.py" file to test the authentication functionality of the "get_all_notebooks" route. This test case sends a GET request to the route without providing any credentials and asserts that the response status code is 401 Unauthorized. 5. Updated the commit message to include the changes made in the previous commits. * Support user login. (#294) * Support user login. (#294) * Fix authentication error in test_notebook_route.py * Refactor authentication logic and update API calls to use token-based authentication
- Loading branch information