Creating token on behalf of user from confidential client

We have some custom flows already implemented in Python (QR login, and login through an external provider for an OTP) and would like to reuse these in keycloak.

Is there some way of getting a new token pair for an already authenticated user from a confidential client to then send it back outside of keycloak’s workflows?