msgraph-sdk-dotnet-core icon indicating copy to clipboard operation
msgraph-sdk-dotnet-core copied to clipboard

Default Client Options

Open maisarissi opened this issue 10 months ago • 2 comments

I used Kiota to generate a customized .NET client library targeting the Graph API and have added the Graph .NET core library to my project.

When creating a new BaseGraphRequestAdapter users can pass their own clientOptions what might be a strange scenario since the clientOption is used to inject telemetry data around SDK versioning.

We should have a default client option where in an absence of a user using service library version, we set up the core library values as default, so when creating a new adapter, the core version will be sent to out telemetry.

maisarissi avatar Aug 22 '23 17:08 maisarissi

After taking a look at this, the only mandatory parameter for BaseGraphRequestAdapter is the authprovider similar to the Kiota abstractions HttpClientRequestAdapter. It is possible to not pass the clientOptions and the SDK will initialize a default as captured in this test

Currently, the initialization with core library is as below.

var authProvider = new AzureIdentityAuthenticationProvider(interactiveBrowserCredential, scopes: scopes);
var graphClient = new ApiClient(new BaseGraphRequestAdapter(authProvider));// Create the API client
var messages = await graphClient.Me.Messages.GetAsync();

andrueastman avatar Aug 23 '23 06:08 andrueastman

Adding more context.

We should have a RequestAdapter factory on core that would provide something like this:

var scopes = new [] { "User.Read" };

var options = new DeviceCodeCredentialOptions
{
    ClientId = "..."
};

var credential = new DeviceCodeCredential(options);

// For inspiration only. Please provide better naming :D
var client = new TinyGraphClient(MicrosoftGraphClientCore.CreateRequestAdapter(credential, scopes));

sebastienlevert avatar Mar 19 '24 14:03 sebastienlevert