Api-platform: API Platform and Voters - $subject variable is null

Created on 24 Jul 2019  路  3Comments  路  Source: api-platform/api-platform

Hello.

I have a basic setup of API platform generated from api-platform/api-platform . I just removed greetings and added Product and ProductVariant entities and configured JWT token auth (https://api-platform.com/docs/core/jwt/).

There was some other bugs, but let's say it works fine.

Now I want to add Voter so I can do a custom permission checks. I created a Voter, tagged it in services.yaml and added proper annotations to an Entity and the app does call my voter.

But problem is that $subject variable always has NULL value. See following screenshots so you understand what I mean:

image

image

TL;DR

dump($subject) prints me NULL , always.

Is this bug or what?

Thanks in advance.

Most helpful comment

You have to pass the object in the access control like:

"access_control"="is_granted('ROLE_USER', object)"

All 3 comments

You have to pass the object in the access control like:

"access_control"="is_granted('ROLE_USER', object)"

Thanks Juan.

Will check when I get some time.

@JuanWilde Awesome. That's it.

Thanks Juan.

Was this page helpful?
0 / 5 - 0 ratings