【发布时间】:2017-10-09 15:43:01
【问题描述】:
我创建了一个新的 asp.net core 2 Web 应用程序。我正在使用个人用户帐户并添加了我的 Microsoft 帐户以进行外部身份验证。所有这些都按预期工作。
现在我想使用 Microsoft Graph 来读取我的 .live 个人资料并最终读取我的邮箱和类似的东西。
我创建了一个身份验证提供程序,并且能够取回访问令牌,但是为什么我尝试使用访问令牌,虽然我的 clientId 和密码输入正确,但我收到了 Authorization_IdentityNotFound 错误。
我认为这是因为我没有使用正确的参数来请求访问令牌。我想我错过了登录 .live 帐户时通常返回的授权响应代码。
有谁知道如何检索该响应代码或在 asp.net core2 中有一个工作示例。我能找到的唯一示例是在 .net core 1.1 中,从那时起情况发生了巨大变化。
【问题讨论】:
-
一些示例代码和有关您如何注册的详细信息会有所帮助
-
我创建了一个 IAuthenticationprovider AuthenticationContext ac = new AuthenticationContext("login.microsoft.com/common/oauth2/v2.0/token");
-
我创建了一个 IAuthenticationprovider AuthenticationContext ac = new AuthenticationContext("login.microsoft.com/common/oauth2/v2.0/token"); ClientCredential creds = new ClientCredentials(cid, secret); authenticationresult ar=await ac.acquiretokenasync("graph.microsoft.com/",creds); request.headers.authorization = new system.net.http.headers.authenticationheadervalue("bearer",ar.accesstoken);然后我提出请求:client.users["..."].request().getasync();
标签: microsoft-graph-api asp.net-core-2.0