Yes, your code is using the auth code flow to get the token, the flow is actually an interactive authentication flow, as you said, you need to interact with the user in the browser to get the authorization code and then use that to redeem an access token.
Depending on your context, if you want to receive tokens automatically, then the auth code flow is obviously not for you, since that flow requires you to have to log in manually.
I'm not sure if you have to use user authentication, if so then I recommend you to use the ROPC flow, as this flow doesn't require a login form, you just have to hardcode your username and password in the code. If you don't have to use user authentication, but only use application principals, a daemon-based client credential flow would be the best option.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.