qsys
03/11/2018, 6:38 PM- operation: Users.read
authenticated: true
query: hasRoleAdmin.graphql
When having a function of type operationBefore
, how can I add authentication/authorization before that function? So:
makeUser:
type: operationBefore
operation: User.create
handler:
code:
src: ./src/befores/createUser.ts
environment:
...
Inside the src/befores/createUser.ts
function, I call an external service, and if that one succeeds, another user can be created. However, this logic may only be executed when the user has proper rights. For now, it seems that adding:
- operation: Users.read
authenticated: true
query: hasCreateUserPermission.graphql
the query logic is executed 'after' the operationBefore query, which leads to weird results (on the external service, some stuff is added, but not on graphcool, since the user is not authorized to do so. I'd prefer to have the authentication logic be executed before the request pipeline.
What is the intended behaviour?
And if it is intended that the authentication is executed as the last one in the request pipeline, how to move it to the front of the pipeline?max
03/11/2018, 9:21 PMoperationBefore
max
03/11/2018, 9:21 PMcreateUser
and do the permission checking in theremax
03/11/2018, 9:23 PMif (!event.context.auth || !event.context.auth.nodeId) {
return { error: 'No user logged in.' }
}
max
03/11/2018, 9:23 PM// create graphcool api using the user's token
const graphcool = new Graphcool(
event.context.graphcool.serviceId || event.context.graphcool.projectId!,
{
token: event.context.auth.token,
endpoints: event.context.graphcool.endpoints,
},
)
const api = graphcool.api('simple/v1')
max
03/11/2018, 9:24 PMqsys
03/14/2018, 8:33 AMmax
03/14/2018, 9:54 AMqsys
03/14/2018, 11:09 AMmax
03/14/2018, 1:50 PMmax
03/14/2018, 1:50 PMqsys
03/14/2018, 1:58 PMoperationBefore
, the permission queries will only be called after that operation, and before the User.create
, right? That's not the aim: the aim is to check first if a user has rights to do something, and than do everything as one atomic operation (operationBefore
+ User.create
). There is no api to call, just a mutation query with an operationBefore. authorization must be checked before.max
03/14/2018, 2:35 PMsignup
max
03/14/2018, 2:35 PMcreateUser
. That's what I didmax
03/14/2018, 2:37 PMcreateUser
is limited to super users and everyone else uses a different function. It means you can split out the permissions and business logic keeping it simpleqsys
03/14/2018, 2:41 PMqsys
03/14/2018, 2:41 PMqsys
03/14/2018, 2:42 PMoperationBefore
, the external call, is executed before authorization.qsys
03/14/2018, 2:43 PMauthorize
-> operationBefore
(external call) -> createUser
qsys
03/14/2018, 2:43 PMoperationBefore
(external call) -> authorize
-> createUser
qsys
03/14/2018, 2:44 PMmax
03/14/2018, 2:44 PMcreateUser2
or a better name. You can do the permission checking in there manually then call createUser
?qsys
03/14/2018, 2:44 PMqsys
03/14/2018, 2:44 PMqsys
03/14/2018, 2:45 PMqsys
03/14/2018, 2:45 PMmax
03/14/2018, 2:45 PMqsys
03/14/2018, 2:46 PMqsys
03/14/2018, 2:46 PMmax
03/14/2018, 2:48 PMmax
03/14/2018, 2:48 PMqsys
03/14/2018, 2:51 PM