Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle authorization #2

Open
J0eppp opened this issue May 17, 2021 · 3 comments
Open

Handle authorization #2

J0eppp opened this issue May 17, 2021 · 3 comments
Assignees
Labels
discussion Discuss a certain topic

Comments

@J0eppp
Copy link
Contributor

J0eppp commented May 17, 2021

Discussion/documentation about how we want to handle the authorization for the REST API.

@J0eppp J0eppp added the discussion Discuss a certain topic label May 17, 2021
@J0eppp
Copy link
Contributor Author

J0eppp commented May 17, 2021

Steps

  1. Identify every database request.
  2. Check if the user has that permission in the database.
  3. If the user has the right permission, continue, else, return 401 - not authorized.

Example

  1. Teacher requests GET /users/<userame/userid> with a valid session.
  2. Server receives request, checks if the user has the GetUser permission.
  3. Teacher has the Getuser permission. Database fetches the data from the requested user and returns it to the client.

@J0eppp J0eppp self-assigned this May 17, 2021
@J0eppp
Copy link
Contributor Author

J0eppp commented May 17, 2021

This is an example on how we could see whether someone has the permission to perform a certain action.

Definitions

00000000 = 0 = NO PERMISSIONS
00000001 = 1 = READ OWN PROFILE
00000010 = 2 = WRITE OWN PROFILE
00000100 = 4 = READ ALL STUDENT'S PROFILES
00001000 = 8 = WRITE ALL STUDENT'S PROFILES
00010000 = 16 = READ ALL PROFILES
00100000 = 32 = WRITE ALL PROFILES
01000100 = 64 = CREATE NEW PROFILES
10000000 = 128 = DELETE PROFILES

Note: these are just examples

Calculation

To check whether a user has the permission to perform a certain action, you do the following:
USER_PERMISSION_INTEGER | PERMISSION_TO_CHECK === USER_PERMISSION_INTEGER

Example

User has the permission to read and write it's own profile
USER_PERMISSION_INTEGER = 3 = 00000011
The user requests to see it's own profile so:
PERMISSION_TO_CHECK = 1 = 00000001
USER_PERMISSION_INTEGER | PERMISSION_TO_CHECK === 3 = 00000011 | 00000001 === 00000011

@showengineer
Copy link

I approve the use of bitfields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Discuss a certain topic
Projects
None yet
Development

No branches or pull requests

2 participants