Skip to content

Instantly share code, notes, and snippets.

@crwang
Last active February 11, 2020 16:41
Show Gist options
  • Save crwang/9907987 to your computer and use it in GitHub Desktop.
Save crwang/9907987 to your computer and use it in GitHub Desktop.
Node JS request to get an oauth token with grant_type of password (to our doorkeeper endpoint)
var default_headers, site_root = 'http://localhost:3000';
default_headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-us,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
// 'Connection': 'keep-alive',
'Cache-Control': 'max-age=0'
};
request({
url: site_root + '/oauth/token',
headers: default_headers,
method: 'POST',
json: {
grant_type: 'password',
client_id: '0887ed9742c581db11f533e72d96e0c1f5b98e65efe08f6b309a45d99add63b3',
client_secret: '75efe6d4d831c79d0c3671875bd2668ee944edbddf37a72b7a2197477e8906bb',
username: '[email protected]',
password: 'doorkeeper'
}
}, function(err, res, body) {
if (!err && res.statusCode == 200) {
console.log(body.access_token);
} else {
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment