Use Node as query-Parameter

Hello,

I built a Controller in Neos whose Actions are accessible via an URL-Endpoint. The Index-Action returns an html which is built in a Fusionfile using afx. As long as all my parameters were simple types everything worked fine. But I want to sent nodes to this Endpoint and I am a bit lost.
A simplified version of my Action looks like this:

public function indexAction(NodeInterface $aktiver_schwerpunkt)
    {

        \Neos\Flow\var_dump($aktiver_schwerpunkt);
    }

This is the Uri I sent to the:

http://localhost:8081/vcg.iww/index.html?aktiver_schwerpunkt[__contextNodePath]=%2Fsites%2Fvcg-iwwde%2Fnode-6adeq3huuwasi%2Fnode-w6rbhr6bdltyi%40user-admin%3Blanguage%3Dde

I used Fusion:ActionUri to built it, giving it on of my nodes as an argument.

But when I try to call this URL I get following error:

My Policy.yaml looks like this:

privilegeTargets:
  Neos\Flow\Security\Authorization\Privilege\Method\MethodPrivilege:
    'Vcg.IwwFilteredListing:Filter':
      matcher: 'method(Vcg\IwwFilteredListing\Controller\StandardController->(.*)Action())'

roles:
  'Neos.Flow:Everybody':
    privileges:
      -
        privilegeTarget: 'Vcg.IwwFilteredListing:Filter'
        permission: GRANT

What could be the error here, can anyone help?

Greetings,

Sabine

How exactly are you creating the uri just had this code lying around:

uri1 = Neos.Fusion:ActionUri {
    absolute = true
    package = 'Neos.Neos'
    controller = 'Frontend\\Node'
    action = 'show'
    arguments.node = ${documentNode}
}
uri2 = Neos.Neos:NodeUri {
    node = ${documentNode}
}
2 Likes

A possible reason for the auth error is that the contextPath you are using refers to the admin workspace. If the admin session is not active when then request is handled the error makes perfect sense.

If you want to use the authentication from the Neos backend the solution to this usually is to register your controller to use the backend authentication provider like in this example here: Sitegeist.Monocle/Settings.yaml at master · sitegeist/Sitegeist.Monocle · GitHub

This is the relevant part of the flow documantation for that: Security — Flow Framework 8.2.x documentation

1 Like

Thank you very much for your answers. I created the Uri indeed using ActionUri:

  uri = Neos.Fusion:ActionUri {
    package = "Vcg.IwwFilteredListing"
    controller = "Standard"
    action = 'index'
    arguments.aktiver_schwerpunkt = ${q(node).property('zielgruppe').properties.schwerpunkte[0]}
  }

(I cheated a bit on my previously posted url, because I only used the query-params from the genreated uri)

Concerning authentication:
I realized that the URI is working when I create it outside of my admin-Context (for example in preview). Then the query params are “aktiver_schwerpunkt%5B__contextNodePath%5D=%2Fsites%2Fvcg-iwwde%2Fnode-6adeq3huuwasi%2Fnode-w6rbhr6bdltyi%40live%3Blanguage%3Dde” and it works.
So my question is: Is it possible to create that uri from within the neos-Backend but without including the admin-Context in the URI? Because in our usecase we want everybody to be able to use this uri.

Use the live workspace for that, that should be visible to anybody:

arguments.aktiver_schwerpunkt = ${q(node).context({'workspaceName':'live'}).property('zielgruppe').properties.schwerpunkte[0]}
2 Likes

Awesome, that works, thank you!

Two last questions: Is there a possibility to send the whole current node via Uri? I tried

    arguments.node = ${q(node).context({'workspaceName':'live'})}

but the Uri that is returned (http://localhost:8081/vcg.iwwfilteredlisting/standard/index?aktiver_schwerpunkt[__contextNodePath]=%2Fsites%2Fvcg-iwwde%2Fnode-6adeq3huuwasi%2Fnode-w6rbhr6bdltyi%40live%3Blanguage%3Dde&node[0][__contextNodePath]=%2Fsites%2Fvcg-iwwde%2Finhalte%2Fnode-iig7922v088jt%40live%3Blanguage%3Dde) gives me the error:

And secondly: I would like to create this link in my afx-Renderer, can I do that?

Thanks again for your quick help!

That should do:

arguments.node = ${q(node).context({'workspaceName':'live'}).get(0)}
3 Likes

That works, thanks so much!