Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure functions 如何从Azure函数调用Microsoft Graph_Azure Functions_Microsoft Graph Api - Fatal编程技术网

Azure functions 如何从Azure函数调用Microsoft Graph

Azure functions 如何从Azure函数调用Microsoft Graph,azure-functions,microsoft-graph-api,Azure Functions,Microsoft Graph Api,实际上,我一直在尝试在Azure函数中调用Microsoft graph API(启用了应用程序身份验证服务)。我的函数使用javascript(节点)运行 实际上,我可以从req.headers(x-ms-token-aad-id-token,x-ms-token-aad-access-token等)中获得一些令牌 我找到了。在我更新并保存functions.js文件之后,当我尝试(通过浏览器)调用该函数时,绑定不起作用,因为该函数获取http404 我还尝试在请求头中使用x-ms-token

实际上,我一直在尝试在Azure函数中调用Microsoft graph API(启用了应用程序身份验证服务)。我的函数使用javascript(节点)运行

实际上,我可以从
req.headers
x-ms-token-aad-id-token
x-ms-token-aad-access-token
等)中获得一些令牌

我找到了。在我更新并保存
functions.js
文件之后,当我尝试(通过浏览器)调用该函数时,绑定不起作用,因为该函数获取
http404

我还尝试在请求头中使用
x-ms-token-aad-id-token
令牌(
Authentication:Bearer xxx token xxx
)手动进行验证,但得到错误响应:

“访问令牌验证失败。访问群体无效。”

我尝试使用
@microsoft/microsoft图形客户端
,得到了相同的消息。可能是我的功能和aad应用程序注册之间的配置问题

const-token=req.headers['x-ms-token-aad-id-token'];
试一试{
const client=graph.client.init({
authProvider:(完成)=>{
完成(空,令牌);
}
});
const user=await client.api('/me').get();
context.log(用户);
}捕获(e){
context.log(e);
}

这里有几个问题:

  • URI
    https://graph.microsoft.com/me
    无效,路径中缺少版本号。根URI应该是
    https://graph.microsoft.com/v1.0

  • 使用客户端凭据进行身份验证时(即没有用户),没有
    /me
    /me/
    段是您传递给我的令牌中经过身份验证的用户的
    /users/{id}
    的别名。由于您没有“经过身份验证的用户”,因此将
    /me
    转换为
    /user/null
    ,显然不存在(
    404

  • x-ms-token-aad-id-token
    不是访问令牌,而是id令牌。此外,它几乎肯定是针对您想要的资源或范围发布的(
    无效受众
    )。您的函数需要使用所需的作用域为自己检索所需租户的令牌

  • 您需要显式传递用户Id或用户主体名称(也称为UPN):


    好的,我想我明白了。。。我从中获得了一个访问令牌,然后我使用该访问令牌呼叫。但是现在我得到了一个错误:“Authorization\u RequestDenied:没有足够的权限来完成操作。”。在我的应用程序注册/api权限中,我已经拥有User.Read和User.ReadBasic.All授权您需要注册
    User.Read.All
    并获得应用程序id的管理员同意。
    User.Read
    User.ReadBasic。所有
    都是授权的,而不是应用程序范围。
    
    https://graph.microsoft.com/users/username@domain.onmicrosoft.com