[英]How Microsoft Graph API OnlineMeeting authenticates Attendee
[英]Microsoft Graph OnlineMeeting API returning Status: NotFound (404) error
我正在嘗試使用以下代碼創建在線會議並傳遞應用程序注冊的所有詳細信息。 仍然返回 404 錯誤。
static string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(LaiAppClientID).WithClientSecret(Secret).WithRedirectUri(redirectURI).Build();
AuthorizationCodeProvider authProvider = new AuthorizationCodeProvider(app, scopesssss);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
graphClient = new GraphServiceClient("https://graph.microsoft.com/beta",
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
var token = await app.AcquireTokenForClient(scopesssss).WithAuthority(String.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", tenantID), true).ExecuteAsync();
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token.AccessToken);
}));
var onlineMeeting = new OnlineMeeting
{
StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
Subject = "My First MS Teams Meeting",
AudioConferencing= audioConferencing
};
var task = Task.Run(async () =>
{
return await graphClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);
});
var d = task.Result;
如您的代碼所示,您使用授權代碼流獲取訪問令牌,然后通過 MS Graph API 創建在線會議。請查看我的代碼,它運行良好。
string clientId = "<your-client-id>";
string clientSecret = "<your-client-secret>";
string redirectUri = "<your-redirect-url>";
string authority = "https://login.microsoftonline.com/<tenant>";
string authorizationCode = "<the authorization code>";
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
IConfidentialClientApplication app = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithRedirectUri(redirectUri)
.WithClientSecret(clientSecret)
.WithAuthority(authority)
.Build();
AuthorizationCodeProvider auth = new AuthorizationCodeProvider(app, scopes);
GraphServiceClient graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) => {
// Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
var authResult = await app.AcquireTokenByAuthorizationCode(scopes, authorizationCode).ExecuteAsync();
// Add the access token in the Authorization header of the API request.
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
})
);
var onlineMeeting = new OnlineMeeting
{
StartDateTime = DateTimeOffset.Parse("2021-07-12T21:30:34.2444915+00:00"),
EndDateTime = DateTimeOffset.Parse("2021-07-12T22:00:34.2464912+00:00"),
Subject = "My First MS Teams Meeting"
};
await graphServiceClient.Me.OnlineMeetings.Request().AddAsync(onlineMeeting);
筆記:
authorizationCode : auth code flow 需要先獲取到這個code,然后才能獲取到API的access token。看到這一步,你可以通過瀏覽器請求url,然后用用戶登錄,然后它就會響應這個code。
權限:要讓它工作,您需要添加權限(您的應用程序 -> API 權限 -> MS Graph ->委派權限-> OnlineMeetings.ReadWrite)以創建在線會議,請參見此處。
參考:
Microsoft Graph API 關於通過 C# 創建在線會議: 鏈接
有關使用AuthorizationCodeProvider
的示例以及有關代碼的更多詳細信息。
更新:
消息:僅 Beta 版支持使用應用程序權限創建在線會議。
API(/v1.0)只支持委托權限(OnlineMeetings.ReadWrite),不支持申請權限。 您可以在之前的注釋中看到這一點。
/beta
也只支持委托權限,見:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.