Coder Social home page Coder Social logo

Comments (5)

luolingchun avatar luolingchun commented on May 18, 2024

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.

image

from flask-openapi3.

 avatar commented on May 18, 2024

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.

luolingchun avatar luolingchun commented on May 18, 2024

oooh,i got it.
I will define a parameter for OpenAPI, then we can pass oauth_config when creating OpenAPI instance.

from flask-openapi3.

luolingchun avatar luolingchun commented on May 18, 2024

@martinatseequent Can you test it? see the demo

from flask-openapi3.

 avatar commented on May 18, 2024

Cool, yes that works, thanks.

from flask-openapi3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.