Nestjs: Access control based on the organization of a user - nestjs

I am writing my first API with NestJS and I am looking for a smart way of managing access to resources. I have the following simplified structure:
organization:
users
products
users:
email
organization
products:
organization
more data
I use Passport JWT and Local strategies. But I want to make sure only users from inside the organization can update and create products for that organization.
I have looked at nest-access-control but can't figure out if it can be used for this.

You can create a third table called 'memberOrganization', with the following columns:
membersOrganization
idMembersOrganization
idUser
idOrganization
idPermission
and a fourth table:
permissions
idPermission
permission
That way you could check if that user is a member of that organization and what permissions they have (using leftJoins). Depending on permission, you allow the creation of such products.
Holpe this helps.

Related

How to implement Django social login using google for different type of users(eg: candidate ,employer, customer)

I want to implement Social login in my Django project. When I searched about it, I found social login for only one user. But I want to implement it for different type of users as I mentioned in the title. Can anyone suggest a solution to implement this in my project.
You can allow auto-registration to everybody. But, to be registered on your app doesn't mean user can do anything in app. Only users on group candidate , employer or customer are allowed to see data or perform operations in app.
Then, you can create views on your app to put users on group. For example, a user of the grup employer can assign users to group customer.

Can't add a new user to create a new organization

I'm writing an API integration for docusign and I wanted to create a second organization for testing, but I can't do it because when I reach the screen to add accounts to the organization, I can't see any accounts listed.
I visit https://admindemo.docusign.com/create-organization
I fill the Name and Description, and press Next
In the Link Accounts page, I see no accounts. How can I add some accounts to this screen?
I'm not sure I understand the relationship between accounts and users, because I have created some users from the Admin>Users screen, but those are not displayed in the account page.
If it isn't asking too much, could I have a short explanation of the difference between these users and what the Organization page asks for, "Accounts"? I remember when I created these "Users", I had to provide an email account, and for me that relationship between Service and Email is what I normally consider an Account.
How can I add some new Accounts to create a second Organization and test the API?
Or, since I want to create more organizations to test if DocuSign has an option to make an organization Primary, is there such an option? I tried browsing the Organization settings but I could not find this.
Can I make one organization the "Primary" organization for an account? How would this be reflected in the response of the API endpoint?
Thank you very much!
Here is a diagram explaining the relationship between organization, accounts, members and users. Hope this make sense.
An account can only belong to a single organization, therefore, you need another account to get another organization (but an organization can have more than one account).

Microsoft GraphAPI: How do I retrieve the assigned groups of an azure user?

As you can see my question above, I was wondering if it is possible to retrieve the assigned groups of an Azure Active Directory (AAD) based user via Microsoft GraphAPI.
My situation is, that I have an ASP.NET MVC project with Microsoft Azure enabled. My goal is, that an Azure user can login on my website with it's Azure account.
The idea is, that an azure user is an admin or an user (depending on the azure groups) and depending of this role group, the user can view more or less of my webpage.
For example:
When Peter logs in with his azure account on my webpage, he should only be able to see:
Add new Document
Edit Document
Remove Document
because he is only assigned as "User" in Azure Active Directory.
But when Sabrina logs in with her azure account on my webpage, then she should be able to do the same as Peter, but she also can see:
Manage Products
Add new customer
etc.
because she is been assigned as an admin in Azure Active Directory.
My problem is, that I did not find out how I retrieve the assigned group of an user with Microsoft GraphAPI. The part, which user can see or not after I got the roles is not a big deal.
I already tried this API call:
https://graph.microsoft.com/v1.0/me/
But it seems, that the response of this call does not include the actual assigned group of that user.
Do you think it is possible to retrieve the assigned group of an azure user? Is this even possible? Or do I have to do something else to retrieve these information?
I hope you understand my point and I am also looking forward for any response. Thanks in advance!
Add /memberOf to the URL to receive the groups a user is member of.
https://graph.microsoft.com/v1.0/me/memberOf
Here's a link to the specific graph api - https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_getmembergroups
Take a look at this sample application on Github. It does something very similar with a task tracker application, where different users are able to perform different actions based on the group they belong to -
https://github.com/Azure-Samples/active-directory-dotnet-webapp-groupclaims/blob/master/README.md
Also, in cases where a user is a member of too many groups, you get back an overage indicator and have to make a separate call to get all groups. Read about “hasgroups” and “groups:src1” claims here - https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-id-and-access-tokens
According to your system architecture, if some user has too many joined groups, the API https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_getmembergroups will return too many groups.
But if the groups with permissions in your system are not too much, you can use this API: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_checkmembergroups to check if the current user is the member of specified groups.
It is not good idea to use this API: https://graph.microsoft.com/v1.0/me/memberOf. Because it returns only the groups that the user is a direct member of, but security group can be member of security group.

How to design a simple role based access control with Mongodb

I'm using mongoose in my nodejs application, I have two Models: an Employee and Organization , I want to attribute some permissions to employees who belong to an organization like inviting or deleting other employees
I've created a mdoel ACL(_id,_empId,_orgId,[permissions]), but I'm not sure if will do the trick
What Models do I have to add in my database, knowing that I need just few permissions

have different roles in different companies symfony 2.0

I'm triying to develop an application which will contain different kinds of companies, and each company will have different roles.
This way, when a superadmin create a company, will define which roles can be attached to this kind of company.
For example, the superadmin could create a shopping center which could have a shop assistant and a director (each of them with different permissions); and another kind of companny which could be a coffee shop, which could have a waiter and a chef.
Then, when an user loggin inside the application, and will want to create a new user, will only have the possibility of select the roles of his kind of company.
But I can't see the way to develop, using the security.yml file and the FOSUserBUndle.
Thanks in advance!
For this kind of purpose, I think you need to implement your security logic inside controllers ; with security.yml you can restrict some entire areas, but I don't think it will help in your case. Maybe you can first define some routes that would be accessible only to some roles (for example, "/waiter/*" for waiters)
Then you can implement like a new kind of roles ; each company can have a field "possible_roles" that will be an array of roles. For example, if a superadmin creates a coffee shop, then you will have possible_roles = { "ROLE_WAITER", "ROLE_CHEF" }
After that you just have to check if the user's role is in the company role's array, and if he has access to the page.
Is it clear ?

Resources