Skip to content

Instantly share code, notes, and snippets.

@khle
Last active March 1, 2016 22:52
Show Gist options
  • Select an option

  • Save khle/6337ed325f0ac174a631 to your computer and use it in GitHub Desktop.

Select an option

Save khle/6337ed325f0ac174a631 to your computer and use it in GitHub Desktop.
var rp = require('request-promise')
const uriAuthToken = 'https://login.windows.net/[YOUR_TENANT].onmicrosoft.com/oauth2/token'
const uriResource = 'http://[YOUR_RESTRICTED_RESOURCE]'
const optionsAuthToken = {
method: 'POST',
uri: uriAuthToken,
form: {
grant_type: 'password',
scope: 'openid',
resource: 'http://samplewebservice.azure-mobile.net', //If you follow my example
client_id: 'client-id-of-the-AAD-native-app',
username,
password
},
json: true
}
rp(optionsAuthToken)
.then(response => {
const optionsResource = {
uri: uriResource,
headers: {
authorization: response.token_type + ' ' + response.access_token
},
json: true
}
return rp(optionsResource)
})
.then(response => {
console.log(response)
}, error => {
console.log("an error occurred", error, error.message, error.stack)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment