Comments (5)
You can do it like this:
from flask_openapi3.models.security import HTTPBearer, OAuth2, OAuthFlows, OAuthFlowImplicit
info = Info(title='book API', version='1.0.0')
jwt = HTTPBearer(bearerFormat="JWT")
oauth2 = OAuth2(flows=OAuthFlows(
implicit=OAuthFlowImplicit(
authorizationUrl="https://example.com/api/oauth/dialog",
scopes={
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
)))
securitySchemes = {"jwt": jwt, "oauth2": oauth2}
class NotFoundResponse(BaseModel):
code: int = Field(-1, description="Status Code")
message: str = Field("Resource not found!", description="Exception Information")
app = OpenAPI(__name__, info=info, securitySchemes=securitySchemes)
security = [
{"jwt": []},
{"oauth2": ["write:pets", "read:pets"]}
]
@app.get('/book/<int:bid>', security=security)
def get_book(path: Path):
...
you will see it.
from flask-openapi3.
Yes, that part is fine. The bit I am after is to pre-poplate the client_id in swagger-ui. That can only be done in JavaScript in the swagger.html template (the window.ui.initOAuth(
bit from above) as it is not part of the OpenAPI spec.
from flask-openapi3.
oooh,i got it.
I will define a parameter for OpenAPI
, then we can pass oauth_config
when creating OpenAPI
instance.
from flask-openapi3.
@martinatseequent Can you test it? see the demo
from flask-openapi3.
Cool, yes that works, thanks.
from flask-openapi3.
Related Issues (20)
- Add support for multiple custom JSON content types in the request body HOT 3
- Flask-sqlalchemy, Flask-migrate, psycopg3 weird behaviour HOT 1
- Is there a work around to create non json request handlers?
- Option to output openapi3 instead of 3.1 HOT 1
- Permissions decorator running after pydantic validation HOT 4
- Shorthand way of describing that the response will be an array of items. HOT 1
- Every route gets a 422 response created HOT 3
- Make body required false
- Not required (optional) fields in multipart/form-data don't have types in swagger HOT 14
- Different endpoints in swagger "Try it out" fire to the same endpoint when they have the same function name HOT 4
- The default value defined in the form is invalid
- incompatibility with latest pydantic 2.5.2 HOT 3
- Apply multi responses to one HttpStatus or apply arbitrary str as responses key HOT 3
- Allow 422 response to specified model not only array HOT 3
- Optional null value with model_fields_set HOT 3
- Missing Pydantic Calculated Fields From openapi.json HOT 3
- How to add examples to swagger HOT 1
- Issues using flask-openapi3 when its views are decorated
- Swagger Validator Error when application is deployed HOT 3
- Pyinstller build breaks docs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-openapi3.