如何使用控制台应用程序通过 Microsoft Graph API 调用 Microsoft Teams OnlineMeeting 端点?
How do I Call Microsoft Teams OnlineMeeting endpoints via Microsoft Graph API using a console app?
我按照下面link微软给出的代码示例成功获取了用户列表。
我在 Azure Active Directory 中注册的应用程序也具有 "OnlineMeeting.ReadWrite.All" 应用程序权限。
但是当我尝试通过在端点“https://graph.microsoft.com/v1.0/me/onlineMeetings”中发布请求来调用创建会议呼叫时。我收到 403 禁止错误。知道我为什么会收到这个吗?
对于图api创建在线会议https://graph.microsoft.com/v1.0/me/onlineMeetings
,我们可以看到tutorial显示它不支持"Application permission"调用它。它只支持 "Delegated permission",所以我们只能通过密码授权流程请求它,而不是客户端凭据流程。
更新:
对于您请求创建在线会议的图表api,我们可以只使用密码授予流程或授权码流程。这里提供一个密码授予流程示例(用户名和密码)供您参考,使用此示例获取令牌并通过此令牌请求图表 api。您也可以在 tutorial 中找到此示例。
static async Task GetATokenForGraph()
{
string authority = "https://login.microsoftonline.com/contoso.com";
string[] scopes = new string[] { "user.read" };
IPublicClientApplication app;
app = PublicClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.Build();
var accounts = await app.GetAccountsAsync();
AuthenticationResult result = null;
if (accounts.Any())
{
result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync();
}
else
{
try
{
var securePassword = new SecureString();
foreach (char c in "dummy") // you should fetch the password
securePassword.AppendChar(c); // keystroke by keystroke
result = await app.AcquireTokenByUsernamePassword(scopes,
"joe@contoso.com",
securePassword)
.ExecuteAsync();
}
catch(MsalException)
{
// See details below
}
}
Console.WriteLine(result.Account.Username);
}
我按照下面link微软给出的代码示例成功获取了用户列表。
我在 Azure Active Directory 中注册的应用程序也具有 "OnlineMeeting.ReadWrite.All" 应用程序权限。
但是当我尝试通过在端点“https://graph.microsoft.com/v1.0/me/onlineMeetings”中发布请求来调用创建会议呼叫时。我收到 403 禁止错误。知道我为什么会收到这个吗?
对于图api创建在线会议https://graph.microsoft.com/v1.0/me/onlineMeetings
,我们可以看到tutorial显示它不支持"Application permission"调用它。它只支持 "Delegated permission",所以我们只能通过密码授权流程请求它,而不是客户端凭据流程。
更新:
对于您请求创建在线会议的图表api,我们可以只使用密码授予流程或授权码流程。这里提供一个密码授予流程示例(用户名和密码)供您参考,使用此示例获取令牌并通过此令牌请求图表 api。您也可以在 tutorial 中找到此示例。
static async Task GetATokenForGraph()
{
string authority = "https://login.microsoftonline.com/contoso.com";
string[] scopes = new string[] { "user.read" };
IPublicClientApplication app;
app = PublicClientApplicationBuilder.Create(clientId)
.WithAuthority(authority)
.Build();
var accounts = await app.GetAccountsAsync();
AuthenticationResult result = null;
if (accounts.Any())
{
result = await app.AcquireTokenSilent(scopes, accounts.FirstOrDefault())
.ExecuteAsync();
}
else
{
try
{
var securePassword = new SecureString();
foreach (char c in "dummy") // you should fetch the password
securePassword.AppendChar(c); // keystroke by keystroke
result = await app.AcquireTokenByUsernamePassword(scopes,
"joe@contoso.com",
securePassword)
.ExecuteAsync();
}
catch(MsalException)
{
// See details below
}
}
Console.WriteLine(result.Account.Username);
}