Role Authentication with Express

Michal Gally

I have a MongoDB of users, each user has property that is user. Users can register, and they get default role of user, but in admin panel, you can create other admins. The problem is I have no idea how to protect from somebody just getting the POST route for creating an user, and just setting the role property as admin and post it with Insomnia for example. Any ideas how to prevent this ?

B.G.

The answer that i can think of is using JWT tokens. Not sure how you can do this with passport.js but you can do it like that :

  1. Only admin user could be able to create an admin account on Web (since you dont wanna create it with using default user account ->just hide the button/option from other users)
  2. You can put info in JWT token (Hence you can add admin-role in JWT to seperates admin request from others or username is enough, you can check the user's role after getting username info from token and get the role from mongo.)
  3. Only an admin can have JWT Token with admin-role. ( JWT token is created when user logged in. You basically hide user's(the one just loged-in) info into the token.)
  4. Put a middleware that anyone does not have JWT token (or have it but not admin role ) cant get into the next().Otherwise return 403.If you let them pass with JWT token only you have to control if the user's role is admin inside the function.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Custom Role with .NET Core 3 Azure AD Authentication

分類Dev

Redirect users depending upon their role after firebase phone authentication

分類Dev

Authentication with NodeJS, Express-Session and Passport fails

分類Dev

How to use Windows authentication to connect to Sql express?

分類Dev

How to mock middleware in Express to skip authentication for unit test?

分類Dev

How to mock middleware in Express to skip authentication for unit test?

分類Dev

How to mock middleware in Express to skip authentication for unit test?

分類Dev

How to properly use express-gateway for authentication of a web app?

分類Dev

NextJS OAuth2 authentication server side without express

分類Dev

NodeJS express Authentication using POST returns Error Cannot Set Headers After they Are Sent

分類Dev

.NET Forms Authentication using IIS8.0 Express (vs2013) - 401.2.: Unauthorized: Logon failed due to server configuration

分類Dev

The role of gradle

分類Dev

express-authenticationを使用してユーザーから特定のタブを非表示にする

分類Dev

Is a role="application" within a role="navigation" valid?

分類Dev

Mifare authentication

分類Dev

Kubernetes:Role vs ClusterRole

分類Dev

UDDI role in webservices?

分類Dev

UDDI role in webservices?

分類Dev

Is role="tooltip" important?

分類Dev

Symfony Role and security explained

分類Dev

Firehose is unable to assume role

分類Dev

Bootstraping Strapi Role Permissions

分類Dev

Role not found error

分類Dev

<ahrefのrole = "button"

分類Dev

Role privileges in Wicket DropDownChoice

分類Dev

Role creation on postgres

分類Dev

ansible playbook execute in this order: task, role, task, role, task

分類Dev

how to create "role" with "Another AWS account" role type by cli command?

分類Dev

How to create 'Security Role' (role entity) through the REST API?

Related 関連記事

  1. 1

    Custom Role with .NET Core 3 Azure AD Authentication

  2. 2

    Redirect users depending upon their role after firebase phone authentication

  3. 3

    Authentication with NodeJS, Express-Session and Passport fails

  4. 4

    How to use Windows authentication to connect to Sql express?

  5. 5

    How to mock middleware in Express to skip authentication for unit test?

  6. 6

    How to mock middleware in Express to skip authentication for unit test?

  7. 7

    How to mock middleware in Express to skip authentication for unit test?

  8. 8

    How to properly use express-gateway for authentication of a web app?

  9. 9

    NextJS OAuth2 authentication server side without express

  10. 10

    NodeJS express Authentication using POST returns Error Cannot Set Headers After they Are Sent

  11. 11

    .NET Forms Authentication using IIS8.0 Express (vs2013) - 401.2.: Unauthorized: Logon failed due to server configuration

  12. 12

    The role of gradle

  13. 13

    express-authenticationを使用してユーザーから特定のタブを非表示にする

  14. 14

    Is a role="application" within a role="navigation" valid?

  15. 15

    Mifare authentication

  16. 16

    Kubernetes:Role vs ClusterRole

  17. 17

    UDDI role in webservices?

  18. 18

    UDDI role in webservices?

  19. 19

    Is role="tooltip" important?

  20. 20

    Symfony Role and security explained

  21. 21

    Firehose is unable to assume role

  22. 22

    Bootstraping Strapi Role Permissions

  23. 23

    Role not found error

  24. 24

    <ahrefのrole = "button"

  25. 25

    Role privileges in Wicket DropDownChoice

  26. 26

    Role creation on postgres

  27. 27

    ansible playbook execute in this order: task, role, task, role, task

  28. 28

    how to create "role" with "Another AWS account" role type by cli command?

  29. 29

    How to create 'Security Role' (role entity) through the REST API?

ホットタグ

アーカイブ