Currently, I'm utilizing a Javascript file in an attempt to acquire a token from ArcGIS Online. Unfortunately, each time I give it a shot, the following error is returned:
init.js:11 Uncaught Error: undefinedModule
The Javascript file (GetAToken.js) in question is displayed below:
dojo.ready(init);
var request = dojo.require('request'); // npm install request
// function to generate a token using client id and client secret
function getToken(callback) {
request.post({
url: 'https://www.arcgis.com/sharing/rest/oauth2/token/',
json: true,
form: {
'f': 'json',
'client_id': '<<MY_CLIENT_ID>>',
'client_secret': '<<MY_CLIENT_SECRET>>',
'grant_type': 'client_credentials',
'expiration': '1440'
}
}, function (error, response, body) {
console.log(body.access_token);
callback(body.access_token);
});
}
In addition, here is the section of code that invokes this function (placed within an HTML file):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://esri.github.io/calcite-bootstrap/assets/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://js.arcgis.com/4.0/esri/css/main.css">
<script src="https://js.arcgis.com/4.0/"></script>
<script src="GetAToken.js">
var MyToken = callback(getToken);
alert(MyToken);
</script>