i am using L5-swagger from DarkaOnLine for my project. I want to use JWT Auth in my documentation. I have added this code :
/**
@OAS\SecurityScheme(
securityScheme="API Key Auth",
type="apiKey",
in="header",
name="Authorization",
)
**/
In swagger UI the "Authorize" button is showed and there is a form to fill with token. But after i enter it, i still got "token_not_provided" error in function that need token to access it.
Thanks in advance.
Token-based Authentication To retrieve a token via our Swagger UI, send a POST request like the following to the /api-token-auth/ endpoint. Copy the token generated from the response, excluding the quotation marks. Click the Authorize button and enter "Bearer", followed by the token from step 2. Click Authorize.
@OAS
annotations are for OpenAPI 3.0, where Bearer authentication is defined as type: http
+ scheme: bearer
:
/**
@OAS\SecurityScheme(
securityScheme="bearerAuth",
type="http",
scheme="bearer"
)
**/
Make sure your operations use security
with the same name as specified in securityScheme="<NAME>"
above. For example:
/**
* @OAS\Get(
* ...
* security={{"bearerAuth":{}}}
* ...
In Swagger UI's "Authorize" dialog, enter the token without the "Bearer" prefix.
this link solved my problem. Bearer Authorization setup
I used this for Laravel Lumen, JWT authentication.
Add this somewhere in your middleware or any other place like base controller
/**
* @OA\SecurityScheme(
* type="http",
* description="Login with email and password to get the authentication token",
* name="Token based Based",
* in="header",
* scheme="bearer",
* bearerFormat="JWT",
* securityScheme="apiAuth",
* )
*/
And add this to your action/function.
/**
* @OA\Get(
* path="/resources",
* summary="Get the list of resources",
* tags={"Resource"},
* @OA\Response(response=200, description="Return a list of resources"),
* security={{ "apiAuth": {} }}
* )
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With