thevahidal / soul

🕉 A SQLite REST and realtime server
https://thevahidal.github.io/soul/
MIT License
1.51k stars 51 forks source link

Authentication Tasks #149

Closed AbegaM closed 4 months ago

AbegaM commented 7 months ago

Feb 14, 2024

Tasks

Features that will be executed when soul boots up

AbegaM commented 7 months ago

Feb 15, 2024

Tasks

AbegaM commented 7 months ago

Feb 19, 2024

Tasks

IanMayo commented 7 months ago

Return the user data by removing the salt and the password

For create only a success report is returned: https://github.com/thevahidal/soul/blob/main/docs/api/rows-examples.md#2-insert-a-new-row

AbegaM commented 7 months ago

Return the user data by removing the salt and the password

For create only a success report is returned: https://github.com/thevahidal/soul/blob/main/docs/api/rows-examples.md#2-insert-a-new-row

ok, i will update the task description 👍

AbegaM commented 7 months ago

Feb 20, 2024

Tasks

AbegaM commented 7 months ago

Feb 22, 2024

Tasks

Fix PRs based on provided commetns

AbegaM commented 7 months ago

Feb 26, 2024

Tasks

AbegaM commented 7 months ago

Feb 27, 2024

Tasks

AbegaM commented 7 months ago

Feb 28, 2024

Tasks

Fix Comments on this PR, #148

AbegaM commented 7 months ago

Testing the Authentication Feature

1. Running soul In Auth mode

1.1 Description

1.2 Steps to run Soul in development mode

  1. Add these config variables in your .env file

    AUTH=true
    
    ACCESS_TOKEN_SECRET=ABCD23DCAA
    ACCESS_TOKEN_EXPIRATION_TIME=10H
    
    REFRESH_TOKEN_SECRET=ACDED22CCC
    REFRESH_TOKEN_EXPIRATION_TIME=10H
    
    INITIAL_USER_USERNAME=<user_name> 
    INITIAL_USER_PASSWORD=<password>
  2. Run this command in your terminal to run Soul in Auth mode

    npm run dev

1.3 Steps to run Soul in CLI mode

  1. Go the the package.json file and manually update the cli script

    "scripts": {
       "cli": "nodemon src/server.js --database foobar.db --atuh --ats <your_secret> --atet 10H --rts <your_secret> --rtet 3D --iuu <user_name> --iup <password>",
     },
  2. Run the cli script in your terminal

    npm run cli

1.4 What to expect from the above steps

2. Obtain access token feature

2.1 Description

2.2 Steps to Obtain Access Token

  1. Go to your HTTP client such as Postman and send a request to this endpoint

    POST localhost:8000/api/auth/token/obtain
    
    BODY {
       "fields": {
         "username": "<user_name>",
         "password": "<password>"
        }
     }
  2. Check the API response, you should get the user ID and a success message

    {
       "message": "Success",
       "data": {
           "userId": 2
       }
    }

3. Elevate users to superuser feature

3.1 Description

3.2 Steps to elevate a default user to a superuser

  1. Go to the package.json file and update the CLI script

    "scripts": {
       "cli": "nodemon src/server.js --database foobar.db updateuser --id=1 --is_superuser=true"
     },
  2. Check if the users status is changed, by using DB Browser For SQLite

    You can check the _users table to check if the is_superuser column has been changed to "true" for the user

4. Change password feature

4.1 Description

4.2 Steps to change password from the API

  1. Open your HTTP client and send a request to this API

    PUT localhost:8000/api/auth/1/change-password
    
    BODY {
           "fields": {
              "currentPassword": "hello@32C#$",
              "newPassword": "ab12#C$AAv"
            }
      }
  2. Check the response of the API, you should get this kind of response

    {
       "message": "Password updated successfully",
       "data": {
           "id": 1,
           "username": "superuser"
       }
    }
  3. Go to step 2 and try to send a request to the obtain access token endpoint with the new changed password

4.3 Steps to change password from the CLI

  1. Go to the package.json file and update the CLI script

    "scripts": {
       "cli": "nodemon src/server.js --database foobar.db updateuser --id=1 --password=<new_password>
     },
  2. Go to step 2 and try to send a request to the obtain access token endpoint with the new changed password

5. Refresh Access token feature

5.1 Description

5.2 Steps to refresh your access token

  1. Open your HTTP client and send a request to this API

    GET localhost:8000/api/auth/token/refresh

    Note: You don't need to manually send the accessToken or the refreshToken as they are already stored in the cookie. Your HTTP client will automatically include them in the requests.

  2. To check for new refresh and access token values in the Postman "cookie" tab, navigate to the "cookie" section in your Postman application and verify if there are updated refresh and access token values present.

6. Create roles and permissions

6.1 Description

6.2 Steps to create a new role and permissions

  1. Open your HTTP Client and send a request to this API to create a new role named customerService

    POST localhost:8000/api/tables/_roles_permissions/rows
    
    BODY {
     "fields": {
           "name": "customerService"
       }
    }
  2. Chek the response, you should get this kind of response

    {
       "message": "Row inserted",
       "data": {
           "changes": 1,
           "lastInsertRowid": 2
       }
    }
  3. Send a new request to the API below to create list of permissions for the new role

    POST localhost:8000/api/tables/_roles_permissions/rows
    
    BODY {
      "fields": {
           "role_id": "<role_id_of_customerService_role>",
           "table_name": "_users",
           "create": "false",
           "read": "false",
           "update": "false",
           "delete": "false"
       }
    }

    Note: In the example provided above, a permission has been created for the customerService role regarding the _users table. It has been decided that this role will not have any permissions on this particular table.

7. Authorization feature

7.1 Description

7.2 Steps to test the authorization feature

  1. Send a request to any endpoint with the user you created

    GET localhost:8000/api/tables/_users/rows
  2. If the currently logged-in user does not possess the READ permission for the _users table, this step will result in an error indicating the lack of authorization.

    {
       "message": "Invalid Access Token"
    }
AbegaM commented 7 months ago

Mar 01, 2024

Tasks

AbegaM commented 7 months ago

Mar 04, 2024

Tasks

AbegaM commented 7 months ago

Mar 05, 2024

Tasks

AbegaM commented 7 months ago

Mar 07, 2024

Tasks

RubenRuCh commented 6 months ago

Amazing job with the authentication features! Definitively improves a lot the usage of Soul

/tip 10 @AbegaM

opirebot[bot] commented 6 months ago

Hi @AbegaM, @RubenRuCh wants to tip you $10.00 for your amazing work 🥳 @AbegaM go to your settings and make sure your Stripe account is configured, otherwise you won't be able to receive payments. @RubenRuCh you can pay the tip in your dashboard

opirebot[bot] commented 6 months ago

Ups... @RubenRuCh tried to complete the payment of $10.00 as a tip to @AbegaM, but @AbegaM doesn't have their payment account configured yet 😱

Please @AbegaM, go to your settings and complete your onboarding! After that, let @RubenRuCh know so they can start the payment process again.

AbegaM commented 6 months ago

Amazing job with the authentication features! Definitively improves a lot the usage of Soul

/tip 10 @AbegaM

Thank you, @RubenRuCh. I appreciate your feedback.

AbegaM commented 6 months ago

Mar 21, 2024

Tasks

RubenRuCh commented 6 months ago

Amazing job with the authentication features! Definitively improves a lot the usage of Soul /tip 10 @AbegaM

Thank you, @RubenRuCh. I appreciate your feedback.

No problem! Btw were you able to setup your payment account in Opire, so I can finish the payment of the tip?

AbegaM commented 6 months ago

Amazing job with the authentication features! Definitively improves a lot the usage of Soul /tip 10 @AbegaM

Thank you, @RubenRuCh. I appreciate your feedback.

No problem! Btw were you able to setup your payment account in Opire, so I can finish the payment of the tip?

Thank you, @RubenRuCh, but unfortunately, my Stripe account is not working due to some financial regulations in my country. So, you can make the donation to @IanMayo.

RubenRuCh commented 6 months ago

Amazing job with the authentication features! Definitively improves a lot the usage of Soul /tip 10 @AbegaM

Thank you, @RubenRuCh. I appreciate your feedback.

No problem! Btw were you able to setup your payment account in Opire, so I can finish the payment of the tip?

Thank you, @RubenRuCh, but unfortunately, my Stripe account is not working due to some financial regulations in my country. So, you can make the donation to @IanMayo.

Sorry to hear that! I'm willing to make the donation to @IanMayo but unfortunately the Opire bot has being uninstalled from the repo :cry: Could you reinstall it? @thevahidal

thevahidal commented 6 months ago

Hey @RubenRuCh,

Sorry, but I had to uninstall Opire. Soul's main contributors weren't too thrilled with its comments, so I had to let it go. I actually really liked the idea behind Opire, so I installed it in my other projects to keep supporting it. Hopefully, we can still grow together!

AbegaM commented 6 months ago

Mar 25, 2024

Tasks

AbegaM commented 6 months ago

Apr 01, 2024

Tasks