Files
connexion/examples/oauth2
Robbe Sneyders 073f0d446e Update examples for Connexion 3.0 (#1615)
This PR updates the examples for Connexion 3.0 and merges them for
OpenAPI and Swagger.

2 examples required some changes to make them work:
- The reverse proxy example required some fixes to the
SwaggerUIMiddleware to leverage the `root_path` correctly. This is
included in the PR.
- The enforced defaults example requires the json validator to adapt the
body and pass it on. We currently pass on the original body after
validation, and I'm not sure if we should change this. I'll submit a
separate PR to discuss this.
2022-12-30 20:34:19 +01:00
..

==============
OAuth2 Example
==============

This example demonstrates how to implement a resource server with Connexion.
The app will lookup OAuth2 Bearer tokens with the given token info function.

Running:

.. code-block:: bash

    $ pip install --upgrade connexion  # install Connexion from PyPI
    $ python mock_tokeninfo.py &       # start mock in background
    $ python app.py

Now open your browser and go to http://localhost:8080/openapi/ui/ to see the Swagger UI.

You can use the hardcoded tokens to request the endpoint:

.. code-block:: bash

    $ curl http://localhost:8080/openapi/secret   # missing authentication
    $ curl -H 'Authorization: Bearer 123' http://localhost:8080/openapi/secret
    $ curl -H 'Authorization: Bearer 456' http://localhost:8080/swagger/secret