-
Notifications
You must be signed in to change notification settings - Fork 17
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
Is there a solution to pass the (permissions related) "userId" to mutated objects? #262
Comments
Not exactly what you ask for, but you could restrict access to the objects based on the user id with the data-dependent permission feature: {
"permissionProfiles": {
"personal": {
"permissions": [
{
"roles": ["user"],
"access": "readWrite",
"restrictions": [
{
"field": "userId",
"claim": "sub"
}
]
}
]
}
}
} Then, you need to inject the user name into the auth context: import { Project } from 'cruddl';
const project = new Project({
// ...
getExecutionOptions: ({ context }) => ({ authContext: { authRoles: ['user'], claims: { sub: context.userId } } }),
}); You would need to implement your client so it properly sets the user id in the "userId" fields when creating new objects. cruddl would validate that this is present and set to the correct value. In queries, the userId would automatically be filtered. Would that work for you? |
I could use this approach minus the client setting any id in the fields. It's probably not good to let clients inject any ids.
Something like that would maybe provide the solution to only allowing valid users to mutate (and query) their own records, where needed. Thank you very much for your time. |
Just to be clear - with the approach I suggested, the client would not be able to choose their id. Providing anything else than their own ID, which is provided by the So the only downside is that you need to fill the With regards to the |
Scenario: A user creates an object in a collection. The resolvers shoudl inject the "user-id" into the field that is also used for the permissions to display only that user's related records. This is needed in order to prevent the ability of database tampering by clients, who could inject other ids if the clients are to provide said ids.
This is also needed for related collections, which when a mutation is creating or updating or removing objects, should pass said ids to all collections so that only user-related objects are mutated or returned in queries.
I have not found this kind of functionality. Is there something that I could use to achieve this or if not, is there anything planned?
Thank you very much
The text was updated successfully, but these errors were encountered: