3

I want to connect swagger with laravel passport. My swagger config file settings

'passport' => [ // Unique name of security
            'type' => 'oauth2', // The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2".
            'description' => 'Laravel passport oauth2 security.',
            'in' => 'header',
            'scheme' => 'https',
            'flows' => [
                "password" => [
                    "authorizationUrl" => config('app.url') . '/oauth/authorize',
                    "tokenUrl" => config('app.url') . '/oauth/token',
                    "refreshUrl" => config('app.url') . '/token/refresh',
                    "scopes" => []
                ],
            ],
        ],

In laravel controller where I am using annotations

/**
     * @OA\Post(
     *     path="/beauty/list-customer-service-bookings",
     *     tags={"beauty_customer_bookings"},
     *     summary="List Customer Bookings.",
     *     operationId="Beauty_Customer_Bookings",
     *     security={{"passport": {}}},
     * @OA\SecurityScheme(
     *    securityScheme="https",
     *    type="oauth2",
     *    in="header",
     *    name="api_key"
     * ),
     *
     *     @OA\Parameter(
     *         name="customer_id",
     *         in="query",
     *         description="customer id",
     *         required=true,
     *         @OA\Schema(
     *             type="integer",
     *             default="482"
     *         )
     *     ),
     *     @OA\Response(
     *         response=422,
     *         description="validation errors."
     *     ),
     *     @OA\Response(
     *          response="200",
     *          description="Customer Bookings."
     *     ),
     *     @OA\Response(
     *          response="401",
     *          description="auth failed."
     *     ),
     *     @OA\Response(
     *          response="404",
     *          description="Page not found."
     *     ),
     * )
     */

It is not sending the headers which it should. Am I doing anything wrong or something is missing? I need the solution of this but in Laravel with swagger OA 3

Zain Farooq
  • 97
  • 2
  • 9
  • Try changing the `@OA\SecurityScheme` annotation to match how the `passport` security is defined in your config file. I.e. `name="passport"`, `flows=...`, etc. Does this work? – Helen Feb 12 '20 at 10:53
  • @Helen I want bearer token to be passed in other API's headers which we get in login api same like postman. I literally don't know how to do that – Zain Farooq Feb 12 '20 at 11:04
  • There is one option if you are using the security scheme from the l5-swagger config file than you don't need to use securityScheme inside the controller. – Muhammad Dec 03 '20 at 08:32

1 Answers1

0
  • hello friend, you just need to add magic parameter like
    Example :
    security={ 
       {"passport": {}}, 
     },
  • in your swagger comment so that when you enter valid auth credential and passport key than curl generate with passport token.

thank You.

Shivam Parmar
  • 1,520
  • 11
  • 27