I know that I have use @auth directive in the schema to implement the authorization in the schema. I case if my claim contains âisAdminâ: âtrueâ claim, I can write @auth in the below format
But in the given JWT sample above roles are in the array format. My requirement is to allow delete only if the user role is âadminâ or âsuperadminâ. My question here is how I write the @auth directive to check, in the above JWT whether the claim âhttp://abc.xyz.com//rolesâ contains âadminâ or âsuperadminâ. Maybe I need to write rule using âinâ operator. But i donât know how to do it. Can anybody help me to write @auth directive for my requirement? Thanks in advance.
Not currently possible using arrays in Role Based Access Control.
Here was a related discussion:
That was about Booleans, but arrays are not supported either. I know I saw that somewhere here in the forum, just canât find it right now. It might have been when @gja initially walked me through it that I picked that up.
Anyways, the only way to accomplish this right now would be to convert that array to single properties:
Not sure though that you were not trying to use http://abc.xyz.com//roles as the claims portion of your JWT. If that was the case then it would need to look like:
@Naman Thanks for the response. I already added # Dgraph.Authorization line in the bottom of the schema. But my question was how to write the query/add/delete/update condtion when JWT contains the arrary of roles.
Currently, the only way to achieve this is to break the array into single values as @amaster507 mentioned. But we will add support for arrays in RBAC rule in the upcoming release.
@pawan I saw that support has been added for the array logic in the @auth directives on master - is there a way to do the reverse yet where an array is provided in the claims and one/more values are defined in the @auth definition that must be matched to?
Hi @forstmeier,
We did add the reverse support. You can check the example test case.
In short, both claims in JWT Token or auth rules can be array. Important thing to note is the equality check. Equal checks behave on the same line as graphql filters. So for example, say claims are of value [A, B, C] and Auth Rule says [filter: in][C, D, E]. Then C being the match, it will return true. Do let us know if you face any issues
@aman-bansal, can you please provide an example in the form of a GraphQL rule? I cannot figure out how to use the filter operation with @auth ROLE claim.
Basically use the in logic. Which I believe from this discussions can be used with the array being the array from a JWT or from a static array in the rule:
We should continue this discussion in the thread dedicated to operating on the $ROLE array, since it seems like it may actually behave differently than the $USER claim from the tests.