0% found this document useful (0 votes)
32 views3 pages

Flask JWT Auth API Documentation

This API documentation describes authentication and assignment microservices. The authentication microservice allows users to register with a username and password as either a student or tutor, and to login to obtain a JWT token for authentication in other requests. The assignment microservice allows tutors to add, delete, and retrieve assignments, and allows students to submit assignments and view assigned or pending assignments. Requests are authenticated with JWT bearer tokens and include parameters like assignment IDs, descriptions, and deadlines.

Uploaded by

Param Shah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Flask JWT Auth API Documentation

This API documentation describes authentication and assignment microservices. The authentication microservice allows users to register with a username and password as either a student or tutor, and to login to obtain a JWT token for authentication in other requests. The assignment microservice allows tutors to add, delete, and retrieve assignments, and allows students to submit assignments and view assigned or pending assignments. Requests are authenticated with JWT bearer tokens and include parameters like assignment IDs, descriptions, and deadlines.

Uploaded by

Param Shah
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

API documentation

● Auth microservices:

1) Register: Register as either student or tutor with username and password.

Request format :

curl --location --request POST '[Link] \


--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=trial_username_student_1' \
--data-urlencode 'password=param12345' \
--data-urlencode 'user_type=student'

2) login: login with username and password and sign for JWT token which will be
forwarded for other requests.

Request format :

curl --location --request POST '[Link] \


--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcl90eXBlIjoic3R1ZGVudCIsImlhdCI6MTY0Mz
EwMTA0OCwiZXhwIjoxNjQzMTA0NjQ4fQ.a-AQIrsqJQcQMoHzB1431Snyvh4mxfZEv4ewhtfnU9c' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=trial_username_student' \
--data-urlencode 'password=param1234'

● Assignment services :

1) Add Assignment: only the tutor is allowed to add assignment with required
fields.

Request format:
curl --location --request POST '[Link] \
--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwidXNlcl90eXBlIjoidHV0b3IiLCJpYXQiOjE2
NDMwOTM2MjYsImV4cCI6MTY0MzA5NzIyNn0.cGq1cA3JqkUlJ-XLDxMQtmxHa2Jhtq2iUifZAKSb
X0M' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'description=trial description for that purpose' \
--data-urlencode 'published_at=1000-01-01 00:00:00.000000' \
--data-urlencode 'deadline_date=1000-05-01 00:00:00.000000' \
--data-urlencode 'studentlist=trial_username_student,trial_username_student_1'

2) Student submission: only students can submit the assignment.

Request format :
curl --location --request POST '[Link] \
--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcl90eXBlIjoic3R1ZGVudCIsImlhdCI6
MTY0MzEwMTEzMSwiZXhwIjoxNjQzMTA0NzMxfQ.JS41szjzt_Qjkg1c5NY5xHGyB4SFOxAXkgeGI
5jxqqE' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'assignment_id=25' \
--data-urlencode 'remark=trial remark for trial purpose'

3) Delete assignment : only the tutor can delete the assignment.

Request format:

curl --location --request POST


'[Link] \
--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcl90eXBlIjoic3R1ZGVudCIsImlhdCI6
MTY0MzEwMTEzMSwiZXhwIjoxNjQzMTA0NzMxfQ.JS41szjzt_Qjkg1c5NY5xHGyB4SFOxAXkgeGI
5jxqqE'

4) Get assignment: Students and tutors can call this API to get their
submitted assignments or assignments uploaded by all the students
incase it is called by tutor.

Request format :

curl --location --request POST '[Link]


\
--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcl90eXBlIjoic3R1ZGVudCIsImlhdCI6
MTY0MzEwMTEzMSwiZXhwIjoxNjQzMTA0NzMxfQ.JS41szjzt_Qjkg1c5NY5xHGyB4SFOxAXkgeGI
5jxqqE'
5) Assignment feed : Students can know their assigned assignments or the
tutor can know the assignments they have uploaded.
In this case there are optional parametersincase published_at is provided
only those assignments will be returned. Incase student is requesting and
asking for assignments with particular status only those will be returned.

Request Format:

Incase of tutor :
curl --location --request POST '[Link]
=2022-01-25T12:51:08.337Z' \
--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcl90eXBlIjoic3R1ZGVudCIsImlhdCI6
MTY0MzEwMTEzMSwiZXhwIjoxNjQzMTA0NzMxfQ.JS41szjzt_Qjkg1c5NY5xHGyB4SFOxAXkgeGI
5jxqqE'

Incase of student:
curl --location --request POST
'[Link] \
--header 'Authorization: Bearer
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcl90eXBlIjoic3R1ZGVudCIsImlhdCI6
MTY0MzEwMTEzMSwiZXhwIjoxNjQzMTA0NzMxfQ.JS41szjzt_Qjkg1c5NY5xHGyB4SFOxAXkgeGI
5jxqqE'

Common questions

Powered by AI

No, a student cannot delete an assignment. The API only allows tutors the permission to delete assignments. This restriction ensures that students cannot modify the availability of assignments that they do not author .

User type determines the actions available to users in the assignment services. Tutors can add, delete, and view all student-submitted assignments, whereas students can only submit assignments and view their own. The API uses JWT tokens, which encode user type, to enforce these permissions and restrict actions accordingly .

To submit an assignment, a student would send a POST request to the '/assignment/submitassignment' endpoint with their JWT token in the Authorization header to authenticate their identity as a student. The request must include form-encoded data specifying the assignment ID and any remarks. This process ensures the submission is correctly attributed to the student and linked to the assignment .

Using the '/assignment/feedassignment' endpoint with improper parameters, like incorrect 'published_at' formatting or a nonexistent 'status', could result in incomplete or erroneous data retrieval. Such issues could cause the client to receive no results or an unfiltered list, causing confusion or additional processing burdens. Correct parameter specification is critical for the intended data output .

The API leverages JWT tokens containing encoded user type information to differentiate between student and tutor actions. Endpoints use this data to enforce role-based permissions, ensuring security and that specific actions, like adding or deleting assignments, are restricted to appropriate user types. Shared endpoints handle user roles carefully to limit access based on these encoded credentials .

HTTP POST requests in the API are crucial as they handle state changes and create actions such as registration, login, assignment submission, and CRUD operations on assignments. POST requests are suitable for sending data securely in the body, preserving confidentiality and security when communicating sensitive information like passwords and JWT tokens. They are essential for executing operations where data changes occur on the server .

Using 'application/x-www-form-urlencoded' is adequate for sending simple structured data, such as form submissions which align with the API's need for handling credentials, assignment descriptions, and submission details. However, it can be less efficient for complex data or larger payloads than JSON, and might increase development complexity if a need for nested data arises. The decision stresses simplicity and compatibility over flexibility .

The JWT token serves as a means of validating and providing credentials for a user's session after login. It allows the API to authenticate subsequent requests by including the token in the request header. This ensures that the requester has the necessary permissions to perform certain actions, such as adding, submitting, or retrieving assignments .

Yes, tutors can use the 'getassignment' API endpoint to retrieve assignments uploaded by students. While the specific filtering for individual students isn't explicitly described, the endpoint supports gaining insights into all submissions, indicating that individual filtering is feasible if coupled with personalized parameters .

The 'published_at' parameter in the assignment feed API is significant as it allows both students and tutors to filter assignments by their publication date. For tutors, it can return only the assignments published after the specified date. For students, additional filters can be applied based on assignment status, such as 'PENDING', allowing more targeted queries .

You might also like