我应该为机器人使用哪个身份验证提供程序?

Which authentication provider should I use for bot?

我已经在 c#.net 中创建了一个 bot 并在团队中部署了该 bot,我想通过使用 graph API 在 bot 中进行会议预订,那么我应该创建哪个 auth provider?

我没有重现你的问题。这是我这边的工作示例。

使用交互式身份验证提供程序

using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using System;

namespace AzureTest
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] scopes = { "https://graph.microsoft.com/.default" };
            IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
                .Create("cbc3***-ac27-4532-802d-303998a6e712")
                .Build();

            InteractiveAuthenticationProvider authenticationProvider = new InteractiveAuthenticationProvider(publicClientApplication,scopes);

            GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);
            User me = graphClient.Me.Request()
                                .GetAsync().Result;
                Console.Write(me.DisplayName);
        }

    }
}

使用机密客户提供商

using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using System;

namespace AzureTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] scopes = { "https://graph.microsoft.com/.default" };
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create("")
                .WithRedirectUri("")
                .WithClientSecret("") 
                .Build();
        }
    }
}

更新:

搜索包时需要勾选include prerelease

现在 Microsoft.Graph.Auth 库已被标记为已弃用,因此接受的答案可能对某些人(比如我)不再有效。

现在您需要使用 Azure.Identity Nuget 包和 InteractiveBrowserCredential 而不是 InteractiveAuthenticationProvider

使用 Microsoft.Graph.Auth 的示例(现已弃用):

string[] scopes = {"User.Read"};

IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
            .Create(clientId)
            .Build();

InteractiveAuthenticationProvider authProvider = new InteractiveAuthenticationProvider(publicClientApplication, scopes);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

User me = await graphClient.Me.Request()
                .GetAsync();

使用 TokenCredential 的示例 class

string[] scopes = {"User.Read"};

InteractiveBrowserCredentialOptions interactiveBrowserCredentialOptions = new InteractiveBrowserCredentialOptions() {
                ClientId = clientId
};
InteractiveBrowserCredential interactiveBrowserCredential = new InteractiveBrowserCredential(interactiveBrowserCredentialOptions);

GraphServiceClient graphClient = new GraphServiceClient(interactiveBrowserCredential, scopes); // you can pass the TokenCredential directly to the GraphServiceClient

User me = await graphClient.Me.Request()
                .GetAsync();

示例取自:https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v4.md