Microsoft C++ 用于图形 API 的 Rest SDK
Microsoft C++ Rest SDK for Graph APIs
我正在尝试使用Microsoft的C++ Rest SDK(https://microsoft.github.io/cpprestsdk/index.html(来调用图形API,但到目前为止,这一直是一场斗争。
在 C# 中,我可以用几行代码完成我的任务。例如,请参阅Microsoft教程中的以下代码:
AuthenticationConfig config = AuthenticationConfig.ReadFromJsonFile("appsettings.json");
bool isUsingClientSecret = AppUsesClientSecret(config);
IConfidentialClientApplication app;
if (isUsingClientSecret)
{
app = ConfidentialClientApplicationBuilder.Create(config.ClientId)
.WithClientSecret(config.ClientSecret)
.WithAuthority(new Uri(config.Authority))
.Build();
}
string[] scopes = new string[] { $"{config.ApiUrl}.default" };
AuthenticationResult result = null;
try
{
result = await app.AcquireTokenForClient(scopes)
.ExecuteAsync();
}
catch (MsalServiceException ex) when (ex.Message.Contains("AADSTS70011"))
{
}
// config.ApiUrl is set to "graph.microft.com"
if (result != null)
{
var httpClient = new HttpClient();
var apiCaller = new ProtectedApiCallHelper(httpClient);
await apiCaller.CallWebApiAndProcessResultASync($"{config.ApiUrl}v1.0/users", result.AccessToken, Display);
}
现在对于跨平台支持,我需要在C++中开发类似的功能,为此,我们正在探索Microsoft C++ Rest SDK。但是我找不到任何好的例子来实现简单的事情,例如提供客户端ID,客户端密码以获取访问令牌和授权。
如果有人遇到任何示例/链接来实现相同的效果,请告诉我。
这里有一些 Dropbox、LinkedIn 和 MS Live scope 中的 oauth 2.0 代码: https://github.com/microsoft/cpprestsdk/blob/master/Release/samples/Oauth2Client/Oauth2Client.cpp
C++ Rest SDK 中的其他示例:
https://github.com/microsoft/cpprestsdk/tree/master/Release/samples
首先,您必须区分:
1. MS 图形身份验证 - 实际上是基于 oauth 2.0(简称:MSAL(的 Azure 访问目录/Microsoft标识平台身份验证
2。使用身份验证过程中的访问令牌访问 MS 图形 API(在标准过程中,应使用 MS 图形 SDK(
对于C++,没有 MSAL 或 SDK 库。 所以 - 为了进行身份验证,你应该使用我上面粘贴的 oauth 2.0 示例。 因为您需要自己编写所有内容,请深入阅读有关 MS Graph 身份验证的文档 https://learn.microsoft.com/en-us/graph/auth/
在这里,您可以查看所有需要的端点、机密等,以获取示例 Postman 调用: https://learn.microsoft.com/en-us/graph/use-postman#set-up-on-behalf-of-api-calls https://developer.microsoft.com/en-us/graph/blogs/30daysmsgraph-day-13-postman-to-make-microsoft-graph-calls/
在 URL 中使用以下变量:
Callback URL: https://app.getpostman.com/oauth2/callback
Auth URL: https://login.microsoftonline.com/**TENANTID**/oauth2/v2.0/authorize
Access Token URL: https://login.microsoftonline.com/**TENANTID**/oauth2/v2.0/token
Client ID: CLIENTID
Client Secret: CLIENTSECRET
Scope: https://graph.microsoft.com/.default
State: RANDOMSTRING
有关 API 调用,请阅读Microsoft图形 REST API v1.0 参考 https://learn.microsoft.com/en-us/graph/api/overview?toc=./ref/toc.json&view=graph-rest-1.0
- Microsoft C++ 用于图形 API 的 Rest SDK
- 如何使用 CPP REST SDK 实现 CAS(中央认证服务)?
- 关于C++ REST SDK 和同步调用
- 使用卡萨布兰卡(C++ REST SDK)的许可条款是什么?
- visual C++ REST SDK a.k.a Casablanka
- C REST SDK(Casablanca) - 如何获得HTTP代理设置
- 将编译器命令行转换为 CMakeLists.txt用于 Casablanca Rest SDK
- 使用 REST SDK 将图像从 OpenCV 3 发送到认知人脸 API C++
- 使用C REST SDK(Casablanca)的HTTP_CLIENT POST请求
- 如何关闭C++ REST SDK websocket
- 卡萨布兰卡 C++ REST SDK 中的 web::json::value::p arse 和 web::json::
- 使用C REST SDK将流响应转换为字节[]
- C++ REST SDK http_listener作为网络服务器
- 关于when_any函数(C++REST SDK)
- 使用 C++ REST SDK (卡萨布兰卡) 从文件中读取 JSON
- C++ REST SDK 中的 URI 编码 ( "Casablanca" )
- C++REST SDK:异步任务与C++11多线程
- 使用 Casablanca REST SDK 将 JSON 字符串转换为C++对象
- 我需要在C++ REST SDK中调用CoInitialize
- 如何通过 REST SDK 接收二进制数据 (protobuf)