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

Support for Bearer Token #4

Open
pedrorjbr opened this issue Aug 15, 2024 · 7 comments
Open

Support for Bearer Token #4

pedrorjbr opened this issue Aug 15, 2024 · 7 comments
Assignees

Comments

@pedrorjbr
Copy link

I am getting this error using it on my fastapi application.

{"errors":[{"status":422,"title":"Input should be 'apiKey', 'basic' or 'oauth2'","detail":"Check this field (securityDefinitions -> HTTPBearer -> BasicAuth -> type) for errors."},{"status":422,"title":"Input should be 'apiKey', 'basic' or 'oauth2'","detail":"Check this field (securityDefinitions -> HTTPBearer -> APIKey -> type) for errors."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> APIKey -> in is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> APIKey -> name is required and cannot be missing."},{"status":422,"title":"Input should be 'apiKey', 'basic' or 'oauth2'","detail":"Check this field (securityDefinitions -> HTTPBearer -> OAuth2Implicit -> type) for errors."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2Implicit -> flow is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2Implicit -> authorizationUrl is required and cannot be missing."},{"status":422,"title":"Input should be 'apiKey', 'basic' or 'oauth2'","detail":"Check this field (securityDefinitions -> HTTPBearer -> OAuth2Password -> type) for errors."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2Password -> flow is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2Password -> tokenUrl is required and cannot be missing."},{"status":422,"title":"Input should be 'apiKey', 'basic' or 'oauth2'","detail":"Check this field (securityDefinitions -> HTTPBearer -> OAuth2Application -> type) for errors."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2Application -> flow is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2Application -> tokenUrl is required and cannot be missing."},{"status":422,"title":"Input should be 'apiKey', 'basic' or 'oauth2'","detail":"Check this field (securityDefinitions -> HTTPBearer -> OAuth2AccessCode -> type) for errors."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2AccessCode -> flow is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2AccessCode -> authorizationUrl is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> OAuth2AccessCode -> tokenUrl is required and cannot be missing."},{"status":422,"title":"Field required","detail":"The field securityDefinitions -> HTTPBearer -> Reference -> $ref is required and cannot be missing."}]}

@virajkanwade
Copy link
Owner

@pedrorjbr what is the version of fastapi and fastapi-swagger2?

@virajkanwade
Copy link
Owner

virajkanwade commented Aug 15, 2024

@pedrorjbr I am not able to reproduce it with latest versions.
Can you please share version details and sample code?

@virajkanwade virajkanwade self-assigned this Aug 15, 2024
@pedrorjbr
Copy link
Author

pedrorjbr commented Aug 15, 2024

This is OpenAPI Json (openapi:3.1.0)
https://api.navigation.carecode.com.br/v1/openapi.json

FastApi Version: fastapi==0.111.0

@virajkanwade
Copy link
Owner

Ahh got it.
HTTP Bearer auth is the issue.
OpenAPI spec 2.0 only supports "basic", "apiKey" or "oauth2".
https://swagger.io/specification/v2/#security-scheme-object

Need to figure out an alternative or atleast handle the error.

@virajkanwade
Copy link
Owner

virajkanwade commented Aug 16, 2024

@pedrorjbr Please use #v0.2.4, It will skip security definitions that are not supported by swagger 2.0 and not crash.

@pedrorjbr
Copy link
Author

pedrorjbr commented Aug 16, 2024

@virajkanwade
Leveraging your experience, my use case is exactly about using the GCP API Gateway and its lack of support for OpenAPI 3. During the CI/CD cycle, I will use the following steps:

Use fastapi_swagger2 to generate the Swagger 2.
From the swagger.json file, I inject the necessary changes, such as the authentication I will use on the GCP API Gateway.
Use an infrastructure as code tool, like Terraform/Pulumi, and apply the changes on GCP.
Well, my question is:
How and where should I expose the API documentation, the OpenAPI file? Could I use the Swagger 2 from step 2 and expose it through a FastAPI route? Would that be the correct way? How would you recommend doing it?

@virajkanwade
Copy link
Owner

virajkanwade commented Aug 16, 2024

@pedrorjbr
General recommendation is never expose the api spec on a production app, unless you are a public api. But even in that case you should only expose the required APIs.

In my case, it was pretty straightforward for me. In the CI/CD pipeline, I added an env var for local. I used to expose both the specs when env var was set to local.
Then using curl, download and save the swagger2 json and using GCP interface in the workflow, upload the spec to APIGW.

In your case, the auth customization you do, if you can automate it, you could do it in a similar way.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants