|
var request = require('request'); |
|
var jwt = require('jsonwebtoken') |
|
function getAccessToken(req) { |
|
/** |
|
* Author:Mauricio Nunes dos reis |
|
* Code to get access token for sharepoint provider hosted apps in context token flow |
|
* Thanks both code above and TokenHelper.cs |
|
*/ |
|
//https://gist.github.com/demelziraptor/9039435 Python |
|
//http://www.getcodesamples.com/src/A39B1460/F692912D PHP |
|
req.session.sp_info = req.query; |
|
req.session.sp_oauth = req.body; |
|
|
|
var client_ID = "{{clientID}}" |
|
|
|
var appSecret = '{{appSecret}}'; |
|
|
|
var decoded = jwt.decode(req.session.sp_oauth.SPAppToken, appSecret) |
|
|
|
decoded.appctx = JSON.parse(decoded.appctx); |
|
|
|
var appctx = decoded.appctx; |
|
|
|
var options = { |
|
headers: { |
|
"Content-Type": "application/x-www-form-urlencoded" |
|
}, |
|
form: { |
|
"grant_type": "refresh_token", |
|
"client_id": client_ID + '@' + decoded['appctxsender'].split('@')[1], |
|
"client_secret": appSecret, |
|
"refresh_token": decoded.refreshtoken, |
|
"resource": decoded['appctxsender'].split('@')[0] + '/' + "<domain>.sharepoint.com" + '@' + decoded['appctxsender'].split('@')[1] |
|
} |
|
}; |
|
|
|
console.log('\noptions\n', JSON.stringify(options)); |
|
var callback = function (req, res, body) { |
|
console.log(JSON.stringify(body)); |
|
} |
|
|
|
request.post(appctx.SecurityTokenServiceUri, options, callback) |
|
} |
Hi,
Thanks for sharing valuable information. I am wondering how do we get the user context token rather than app context token.
Thanks,
Venkat Konjeti