Thanks for reaching out.
I understand you are trying to get the access token using UsernamePasswordCredential class.
However, it is not recommended approach as this class enable authentication using a user's username and password.
This class require high class of trust and carries risks. This class uses OAuth ROPC flow to get the access token and can be used only when other flows are not viable.
There are other alternative classes available using other OAuth flows to get the access token which are more secure.
For non-interactive call, you can use ClientSecretCredential which help to acquire the token using client secret.
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.