hussein4alaa / laravel-g4t-swagger-auto-generate

auto generate swagger in laravel
MIT License
106 stars 13 forks source link

Swagger 'Authorize' not working #70

Closed mouayed-keziz closed 2 months ago

mouayed-keziz commented 2 months ago

Describe the bug in the swagger ui, when opening the authorize section and add an apiKey or a bearer token it doesnt work, i have a working api (auth with sanctum) with laravel, tested with http clients (curl, postman, httpie) and everything works fine, when using the authorize feature of swagger it doesnt add the token to the req

by default the config has two authorization strategies, which are

"authorization" => [
            "type" => "apiKey",
            "name" => "authorization",
            "in" => "header"
        ],
        "apiKey1" => [
            "type" => "apiKey",
            "name" => "key1",
            "in" => "query"
        ],

i added this one

"bearer" => [
            "type" => "http",
            "scheme" => "bearer",
            "bearerFormat" => "JWT",
            "securityScheme" => "bearerAuth",
            "description" => "Enter the token with the Bearer prefix, e.g. `Bearer abcde12345`"
        ]

but when trying to make a request after adding a key (both default strategies or my custom one), the backend responds with 'Unauthorized', when looking at the curl request, it seems like the swagger is not even adding the headers to the request

curl -X 'GET' \
  'http://localhost:8000/api/v1/user/get-infos' \
  -H 'accept: application/json'

To Reproduce Steps to reproduce the behavior:

  1. open the swagger ui
  2. add a key the authorize modal (doesnt matter if its apiKey, bearer)
  3. try to send a request to an endpoing
  4. read the curl output (the issue is that it doesnt add anything to the request)

Expected behavior having the actual token in the request, and having the correct response from the server (authorized)

Screen Shots image image

hussein4alaa commented 2 months ago

dear @mouayed-keziz edit config/swagger.php to add auth_middlewares sanctum

and use default security_schemes auth ss