将 Microsoft Graph REST API 与 Web API 中的后端用户一起使用
Use Microsoft Graph REST API with a back-end user in Web API
我一直在努力寻找一种正确的方法来在 Web api 中对 Microsoft Graph REST API 的完全特权用户进行身份验证。目的是在我的 Web API 上进行用户身份验证,然后使用不同的应用程序执行文件修改,仅供用户在 OneDrive 中修改文件。
这个用例是否有任何资源和提示?我只能找到实际最终用户被重定向以使用 Microsoft 登录名进行身份验证并授予权限的示例。
使用 app only 似乎可行,但我不确定如何将其包含在网络中 API
感谢您的帮助
AuthenticationContext authContext = new AuthenticationContext("AuthURI");
var clientCred = new ClientCredential("ClientID","ClientSecret");
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/...", clientCred);
accessToken = authResult.AccessToken;
var graphserviceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
}));
var drives = await graphserviceClient.Drives.Request().GetAsync();
我一直在努力寻找一种正确的方法来在 Web api 中对 Microsoft Graph REST API 的完全特权用户进行身份验证。目的是在我的 Web API 上进行用户身份验证,然后使用不同的应用程序执行文件修改,仅供用户在 OneDrive 中修改文件。
这个用例是否有任何资源和提示?我只能找到实际最终用户被重定向以使用 Microsoft 登录名进行身份验证并授予权限的示例。
使用 app only 似乎可行,但我不确定如何将其包含在网络中 API
感谢您的帮助
AuthenticationContext authContext = new AuthenticationContext("AuthURI");
var clientCred = new ClientCredential("ClientID","ClientSecret");
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/...", clientCred);
accessToken = authResult.AccessToken;
var graphserviceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
}));
var drives = await graphserviceClient.Drives.Request().GetAsync();