Можно использовать привязку Microsoft Graph, в частности привязку Auth .
Просто убедитесь, что для свойства identity
установлено значение userFromRequest
, а затем вызовите один из API Microsoft Graph , как показано в документе.
Для справки, вот пример из документа
function.json
{
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in"
},
{
"type": "token",
"direction": "in",
"name": "graphToken",
"resource": "https://graph.microsoft.com",
"identity": "userFromRequest"
},
{
"name": "$return",
"type": "http",
"direction": "out"
}
],
"disabled": false
}
C # Script
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Microsoft.Extensions.Logging;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, string graphToken, ILogger log)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", graphToken);
return await client.GetAsync("https://graph.microsoft.com/v1.0/me/");
}
NodeJS / JavaScript
const rp = require('request-promise');
module.exports = function (context, req) {
let token = "Bearer " + context.bindings.graphToken;
let options = {
uri: 'https://graph.microsoft.com/v1.0/me/',
headers: {
'Authorization': token
}
};
rp(options)
.then(function(profile) {
context.res = {
body: profile
};
context.done();
})
.catch(function(err) {
context.res = {
status: 500,
body: err
};
context.done();
});
};