Hi Sophie,
Have you already checked out the OIDC Module? This module already implements the OAuth 2.0 Code Grant flow so probably you can just use this module for your purpose without extra development.
If you still need your own custom development, you can still take this module as an inspiration. E.g. the Step1 is implemented in the OIDC module like this: