Do the oauth dance to get a user's access token, knowing the password.
This is meant for bots, where the machine is going to know the password.
If you're dealing with an end user, you'll need to open a browser and do this properly. You don't want to be handling their password, and they might be using 2FA anyway.
Command line usage
Use mastodon-register-app and mastodon-create-account first, in the same directory, giving you an app-registration.json and user-details-USERNAME.json files, which have data we need to get the tokens.
$ npm install -g mastodon-get-token$ mastodon-get-token test7wrote access-token-test7.json$ cat access-token-test7.json
Library usage
$ npm install --save mastodon-get-token
const getToken = const appreg = const user =