Security
The bundle uses JsonRpcBundle security (ufo_json_rpc.security, see Bundle configuration); there is no separate REST configuration.
# config/packages/ufo_json_rpc.yaml
ufo_json_rpc:
security:
protected_api: true # default: calls require a token
protected_doc: false # default: documentation is open
token_name: 'Ufo-RPC-Token'
clients_tokens:
- '%env(resolve:UFO_API_TOKEN)%'
providers:
partners:
api_groups: [partners]
clients_tokens: ['%env(PARTNERS_TOKEN)%']
internal:
api_groups: [internal]
service: App\Security\InternalTokenValidator # implements ITokenValidator
| Request | Check | Error |
|---|---|---|
| REST call | protected_api: the token from the token_name header is checked by the provider of the entry point's API group, and for groups without a provider, by clients_tokens |
401 |
| OpenAPI / Postman | protected_doc: the same check for the document's group |
401 |
curl https://example.com/internal/catalog/list -H 'Ufo-RPC-Token: internal-secret'
- The group is defined by the route (the import's
defaults.api_group), so a token of one group does not open another group's entry point. Anapi_groupparameter in the request does not change the group. - A provider sets either
clients_tokensorserviceimplementingUfo\JsonRpcBundle\Security\Interfaces\ITokenValidator(Providers for API groups). - JSON-RPC returns
403for an invalid token; REST returns401for both a missing and an invalid one. protected_docdoes not protect calls, andprotected_apidoes not protect documentation: they are two independent flags.- Symfony Security firewalls apply to REST paths the same way as to any other routes.
REST routes do not handle CORS preflight (OPTIONS): if OPTIONS is not in the methods of the #[Route] attribute, the response is 405. Configure CORS at the web server level or with a separate bundle.