Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which authentication provider should I use for bot?

I have created a bot in c#.net and deployed that bot in teams, I want to conference booking in bot by using graph API, so which auth provider should I create?

error

like image 812
Priya Avatar asked Mar 14 '26 02:03

Priya


1 Answers

Now the Microsoft.Graph.Auth library has been marked as deprecated, so the accepted answer maybe is not valid anymore for someone (like me).

Now you need to use Azure.Identity Nuget package and InteractiveBrowserCredential instead of InteractiveAuthenticationProvider.

Example using Microsoft.Graph.Auth (DEPRECATED NOW):

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();

Example using 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();

Examples are taken from: https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/docs/upgrade-to-v4.md

like image 142
Carlos Avatar answered Mar 15 '26 15:03

Carlos