Integrating OpenIdConnect with FastAPI’s OpenAPI UI

FastAPI is a powerful tool for building APIs with Python, but it doesn’t fully support OpenIdConnect out of the box. However, with a bit of tweaking, you can set up FastAPI’s OpenAPI UI (Swagger UI) to use OpenIdConnect authentication across all routes. This is particularly useful if you’re using an identity provider like Keycloak without having to set it inside your routes.

This is particularly useful in combination with the fastapi keycloak plugin, which doesn’t parameterize the openapi part.

What is OpenIdConnect?


OpenIdConnect is an identity layer on top of the OAuth 2.0 protocol, allowing clients to verify the identity of the end-user based on the authentication performed by an authorization server.

Setting Up OpenIdConnect in FastAPI for OpenApi


To set up OpenIdConnect in FastAPI, you need to modify the OpenAPI schema. Here’s an example:

app = FastAPI()
...
if app.openapi_schema:
    app.openapi_schema["components"]["securitySchemes"]["openId"] = {
        "type": "openIdConnect",
        "openIdConnectUrl": "https://yourkeycloakurl.com/realms/yourrealm/.well-known/openid-configuration",
    }
    app.openapi_schema["security"] = [{"openId": ["read", "write"]}]


In this code:

We’re adding a new security scheme to the OpenAPI schema. The type is openIdConnect, and the openIdConnectUrl is the well-known configuration URL of your OpenIdConnect provider (like Keycloak).
We’re setting the security property of the schema to use the OpenIdConnect scheme. The [« read », « write »] array represents the scopes that the OpenIdConnect provider should request. In this case, all our endpoints.


Wrapping Up


This approach allows you to set up OpenIdConnect authentication across all routes in FastAPI’s OpenAPI UI, without needing to manually configure each route. It’s a handy trick if you’re using an identity provider like Keycloak and want to leverage OpenIdConnect for your FastAPI application.

References

Flutter – Scrollable dialog with Getx

To have a scrollable dialog with Getx, you have multiple possibilities.

1. With Get.dialog

Get.dialog(
  Container(
    width: double.maxFinite,
    child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("Description 1",
              style:
                  TextStyle(fontWeight: FontWeight.bold)),
          SizedBox(height: 8),
          Flexible(
            child: SingleChildScrollView(
              child: Text('Very, very large title',
                  textScaleFactor: 15),
            ),
          ),
          ElevatedButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Text("OK"),
          )
        ]),
  ),
);

2. With Get.defaultDialog

Get.defaultDialog(
  content: Flexible(
    child: SingleChildScrollView(
      child: Text('Very, very large title',
                  textScaleFactor: 15),
    ),
  ),
);

3. By combining Get.dialog and AlertDialog

Get.dialog(AlertDialog(
  content: Container(
    width: double.maxFinite,
    child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.min,
        children: [
          Text("Description 1",
              style:
                  TextStyle(fontWeight: FontWeight.bold)),
          SizedBox(height: 8),
          Flexible(
            child: SingleChildScrollView(
              child: Text('Very, very large title',
                  textScaleFactor: 15),
            ),
          ),
          ElevatedButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Text("OK"),
          )
        ]),
  ),
));

Synology – mise à jour de docker-compose

Par défaut les NAS Synology DSM 7 sont livrés avec docker et docker-compose.

Cependant la version de docker-compose est assez ancienne en version 1.xx alors que nous sommes déjà en version 2.13.

Bref, pour faire simple, le mieux est de rajouter dans votre PATH utilisateur, un répertoire et de mettre une version à jour de docker-compose.

Pratique

connectez-vous en ssh sur le nas avec un compte qui peut utiliser docker.

faites un test:

docker-compose -v
docker ps

allez dans votre HOME, => cd

Remarques: faîtes bien le cd , le bash synology DSM7.1 a un problème sur le répertoire par défaut à la connexion.

créez un répertoire bin à la racine de votre HOME dans lequel vous mettrez tous vos binaires.

mkdir bin
nano .bashrc

ajouter:

export PATH="/volume1/homes/monhome/bin:$PATH"

puis appliquer les modifications à la session courante:

source .bashrc

enfin dans le répertoire bin:

cd bin
curl -L https://github.com/docker/compose/releases/download/v2.13.0/docker-compose-`uname -s`-`uname -m` -o docker-compose

changer la version par la dernière présente sur https://github.com/docker/compose/releases/

faites un test:

docker-compose -v