CSC/ECE 517 Fall 2023 - E2379. Reimplement authorization helper.rb
This wiki page is for the information regarding the changes made for the E2379 OSS assignment for Fall 2023, CSC/ECE 517.
Introduction
Expertiza currently uses session-based authentication in its AuthorizationHelper module. The reimplementation back end uses JSON Web Token (JWT) based authentication. This requires a redesign of the AuthorizationHelper module to accommodate JWT-based authentication.
About Helper
The AuthorizationHelper module provides methods to check a user's privileges and roles within the system. It allows you to determine if the current user has specific roles like Super-Admin, Admin, Instructor, TA, or Student. You can also check if the user is a participant in a particular assignment, instructs an assignment, or has TA mappings for an assignment. Additionally, it provides methods to identify if the current user can perform actions like submitting work, reviewing, or taking quizzes. These functions are essential for managing user permissions and access control in the application.
Requirements
- JWT Authentication Integration: Modify the AuthorizationHelper module to integrate JWT-based authentication, allowing users to authenticate and authorize requests using JWT tokens instead of sessions.
- Token Verification: Implement methods to verify and decode JWT tokens to extract user information and permissions.
- Privilege Verification: Update the existing methods (e.g., current_user_has_super_admin_privileges?, current_user_is_a?, etc) to use JWT claims to determine a user's privileges. Users will be granted access based on their role and claims within the JWT.
- User Identity Verification: Implement a method to verify the identity of the current user based on the JWT token. Ensure that the user's role is validated correctly.
- Methods should be updated to use the user's JWT claims.
- Error Handling: Implement appropriate error handling to deal with JWT verification failures or unauthorized access attempts.
Methods to be implemented
- jwt_verify_and_decode(token): This method will verify and decode a JWT token and return the user's information, including role and claims.
- check_user_privileges(user_info, required_privilege): Given user information from the JWT and a required privilege, this method will determine if the user has the required privilege.
- Update and adapt the existing methods to use JWT claims for authentication and authorization.
Deliverables
- A modified and fully functional AuthorizationHelper module with JWT-based authentication.
- Updated methods to ensure JWT claims are used for authentication and authorization.
- Appropriate error handling to handle JWT-related issues.
- Unit tests should cover different scenarios and edge cases to ensure that each function works as expected
- Comments for every function.
JWT Token
A JWT contains three parts:
- Header: Consists of two parts:
The signing algorithm that’s being used. The type of token.
- Payload: The payload contains the claims or the JSON object.
- Signature: A string that is generated via a cryptographic algorithm that can be used to verify the integrity of the JSON payload.