forked from ttezel/twit
-
Notifications
You must be signed in to change notification settings - Fork 4
Getting an access_token with the oauth package
Darius Kazemi edited this page Apr 5, 2017
·
5 revisions
First, get your client_id and client_secret from mastodon as detailed here
var OAuth2 = require('oauth').OAuth2;
var oauth = new OAuth2('your_client_id', 'your_client_secret', 'https://mastodon.social', null, '/oauth/token');
var url = oauth.getAuthorizeUrl({ redirect_uri: 'urn:ietf:wg:oauth:2.0:oob', response_type: 'code', scope: 'read write follow' });
// Get the user to open up the url in their browser and get the code
oauth.getOAuthAccessToken('code from the authorization page that user should paste into your app', { grant_type: 'authorization_code', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob' }, function(err, accessToken, refreshToken, res) { console.log(accessToken); })
If you don't want to run through that whole process, you can use this browser-based tool that walks you through the process.