Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to document Symfony App Roles #2370

Open
micter59 opened this issue Oct 30, 2024 · 4 comments
Open

[Question]: How to document Symfony App Roles #2370

micter59 opened this issue Oct 30, 2024 · 4 comments
Labels
question stale stale issue/PR

Comments

@micter59
Copy link

Version

4.31

Question

Hello.
I'm using this bundle to generate the documentation of an API.
The API is made available through Symfony 6.4 controllers.
Authentication is made through a JW Token, and works correctly.
Even if the user of the API has a JWT, I'm checking his application roles, as not every API endpoints are available to all users.
So in Symfony's API Controller, I'm checking this with the @IsGranted('ROLE_XXX') attribute.
How could I made this appear in the documentation ?

Thanks.

Capture d’écran 2024-10-30 094907

Additional context

No response

@micter59
Copy link
Author

For now, I use the #[OA\Response] to indicate this, but this is not very visible.
I looked for the Security annotation, but this seems not be usable with symfony app roles.
If you have an other idea to do this, don't hesitate to tell me.

@DjordyKoert
Copy link
Collaborator

Have a look at https://symfony.com/bundles/NelmioApiDocBundle/current/security.html

First define your securityScheme(s) in the bundle configuration.

Then use Nelmio's #[Security] attribute #[Security(name: "YourSchemeNameHere", scopes: ['ROLE_API'])]

@micter59
Copy link
Author

micter59 commented Nov 2, 2024

Thanks for your answer. If I understand you well, there will be only 1 securityScheme to check the JWT token, and then the "scope" part of the #[Security] attribute will do the job for the documentation. Am I right ?

Copy link

This issue has been marked as stale because it has not had any activity for 60 days. Remove stale label or comment to prevent this from being closed in 21 days.

@github-actions github-actions bot added the stale stale issue/PR label Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question stale stale issue/PR
Projects
None yet
Development

No branches or pull requests

2 participants