Core: Default value option on Swagger api keys

Created on 25 Oct 2018  路  4Comments  路  Source: api-platform/core

My current project API need this header to authenticate:

Authorization: Bearer your_api_token

So I add this configuration for Swagger:

api_platform:
    swagger:
        api_keys:
            -
                name: Authorization
                type: header

It works. But the customer always have to add Bearer on the form content.

It would be great to have a default_value option on each api_keys element.

Most helpful comment

No I don't want to avoid the usage of the Authorize button, I just want the form content to have Bearer on the input, so the use just have to copy the key. :-)

All 4 comments

I'm not sure if I understand correctly but I'll give a go at responding. If you mean that in the swagger docs a user has to add the Bearer on the form content then that can be done once when the page loads with a little 'Authorize' button that will appear in the docs.

If you mean that you'd like to set a default authorization header so a user doesn't have to do this, would this not make the API insecure because you'd be exposing an API key to the public?

No I don't want to avoid the usage of the Authorize button, I just want the form content to have Bearer on the input, so the use just have to copy the key. :-)

Oh I see, API Platform just creates a swagger config. It looks as though this isn't something that package is looking to support - see https://github.com/OAI/OpenAPI-Specification/issues/583

Mainly due to the potential security issues. Perhaps you could write a kernel listener, check if Bearer is in the authorization header already and if not, prepend it?

In that case, I could simply remove the Bearer prefix. :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

silverbackdan picture silverbackdan  路  3Comments

mahmoodbazdar picture mahmoodbazdar  路  3Comments

vViktorPL picture vViktorPL  路  3Comments

DenisVorobyov picture DenisVorobyov  路  3Comments

rockyweng picture rockyweng  路  3Comments