microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
277 stars 50 forks source link

"Client ID not supplied" warning with AuthenticationType.ExternalTokenManagement and new ctor #314

Closed fowl2 closed 1 year ago

fowl2 commented 2 years ago

Old code:

  new ServiceClient(
      instanceUrl: uri,
      tokenProviderFunction: GetToken,
      useUniqueInstance: true,
      logger: logger);

Result: a bunch of log messages, but no warnings.

Switching to the new constructor:

  new ServiceClient(connectionOptions: new()
  {
    AccessTokenProviderFunctionAsync = GetToken,
    AuthenticationType = Microsoft.PowerPlatform.Dataverse.Client.AuthenticationType.ExternalTokenManagement,
    ServiceUri = uri,
    Logger = logger,
  });

Result: warning Client ID not supplied, using SDK Sample Client ID for this connection logged each time.

edit: My understanding is that a client ID is not required when providing an access token directly. Setting the client ID property to null, "", or a value doesn't seem to have any effect.

MattB-msft commented 2 years ago

@fowl2 , this pattern is extremely common and thus I'm a bit surprised your experiencing an issue.

You in the second example, you do not need to pass the authentication type if you're setting the AccessTokenProviderFunction. The system will set it for you based on the hander being set.

I would suggest starting by adding some logging into your token processor and make sure it's being called.

What OS and version of the client are you using?

fowl2 commented 2 years ago

@fowl2 , this pattern is extremely common and thus I'm a bit surprised your experiencing an issue.

Me too!

You in the second example, you do not need to pass the authentication type if you're setting the AccessTokenProviderFunction. The system will set it for you based on the hander being set.

Ok, I tried removing it. No effect.

What OS and version of the client are you using?

Microsoft Windows [Version 10.0.19042.1889] Microsoft.PowerPlatform.Dataverse.Client 1.0.9

This is just from my development machine running in the Azure Functions emulator, version 4.21 with Visual Studio.

I would suggest starting by adding some logging into your token processor and make sure it's being called.

It definitely being called, see below code and logs:

    public ClientOrgSvcFactory(...)
    {
        _logger.LogInformation("About to call new ServiceClient(...)");
        _serviceClient = new ServiceClient(connectionOptions: new()
        {
            AccessTokenProviderFunctionAsync = GetToken,
            Logger = _logger,
            ServiceUri = uri.Uri,
        });
        _logger.LogInformation("ServiceClient created");
        ...
    }

    async Task<string> GetToken(string instance)
    {
        _logger.LogInformation($"ClientOrgSvcFactory.GetToken({instance})");
        ...
    }

Here's fuller logs:

[2022-09-12T04:55:44.836Z] About to call new ServiceClient(...)
[2022-09-12T04:55:44.890Z] Client ID not supplied, using SDK Sample Client ID for this connection
[2022-09-12T04:55:45.141Z] Attempting to Connect to Uri https://redacted.crm6.dynamics.com/XRMServices/2011/Organization.svc
[2022-09-12T04:55:45.185Z] BuildOrgConnectUri CoreClass ()
[2022-09-12T04:55:45.192Z] BuildOrgConnectUri CoreClass ()
[2022-09-12T04:55:45.193Z] Organization Service URI is 'https://redacted.crm6.dynamics.com/XRMServices/2011/Organization.svc'
[2022-09-12T04:55:45.199Z] ConnectAndInitService - Requesting connection to Organization with Dataverse Version: No organization data available
[2022-09-12T04:55:45.204Z] ClientOrgSvcFactory.GetToken(https://redacted.crm6.dynamics.com/XRMServices/2011/Organization.svc/web?SDKClientVersion=9.2.47.9489)
[2022-09-12T04:55:57.592Z] ConnectAndInitService - Proxy created, total elapsed time: 00:00:12.3932656
[2022-09-12T04:55:57.598Z] Querying Organization Instance Details. Request ID: 90ae5b3e-2180-4d9b-bee1-32775c2bc4d1
[2022-09-12T04:55:57.600Z] Execute Command - RetrieveCurrentOrganizationRequest : RequestId=90ae5b3e-2180-4d9b-bee1-32775c2bc4d1
[2022-09-12T04:56:00.535Z] Executed Command - RetrieveCurrentOrganizationRequest : RequestId=90ae5b3e-2180-4d9b-bee1-32775c2bc4d1 : total duration: 00:00:02.9359395
[2022-09-12T04:56:00.540Z] Connected to User Organization (redacted version: 9.2.22084.180)
[2022-09-12T04:56:00.541Z] Direct Login Process Succeeded - duration 00:00:15.4007511
[2022-09-12T04:56:00.543Z] ServiceClient created
MattB-msft commented 2 years ago

@fowl2 this reflects that client is created and working, is it not? IE are you commenting about the warnings in the logs?

fowl2 commented 2 years ago

Sorry for being unclear - everything seems to work, but there's an erroneous warning message.

MattB-msft commented 2 years ago

Got it,. We will take a look at that warning message and see if we can get rid of it under this circumstance.

thanks for Reporting it!

fowl2 commented 1 year ago

I have updated Microsoft.PowerPlatform.Dataverse.Client to version 1.0.26, but am still receiving the warning Client ID not supplied, using SDK Sample Client ID for this connection when using the public ServiceClient(ConnectionOptions connectionOptions, bool deferConnection = false, ConfigurationOptions serviceClientConfiguration = null) ctor.