0
votes

I followed the quickstart here: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/enhanced-quick-start

Which worked great, so then I need to register my app, so I followed this: https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/walkthrough-register-app-azure-active-directory

But now my unit tests give me the error:

Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException: AADSTS65001: The user or administrator has not consented to use the application with ID '[GUID]' named '[AppName]'. Send an interactive authorization request for this user and resource.

I feel like I understand the error, that the administrator needs to consent. My program is doing some magic in the bakcgorund and the user is not signing in, it is using a set username and password and the user should not be consenting to anyone. Is there any way to set this consent permanently, or force it every time through the Helper class in the first tutorial? All my Google-fu came up empty... Thank you.

1
You should be using ClientId and ClientSecret to authenticate and not Username Password. And when you Created the AppRegistration in Azure have you selected Delegate ?minohimself
Microsoft's own docs use the username/password (link above) - can you point me to a ClientSecret example?naspinski
I have seen all those articles, and they all show old versions of everything - most importantly the delegate permissions. I switched to ClientId and ClientSecret and I am getting the same error. Anyone know where a more recent guide to the Dynamics delegate permissions?naspinski
Did you tried the connections i posted ? Try to create the app registration from scratch. I never had problem with thatminohimself

1 Answers

1
votes

You can use something like this:

CrmserviceClient is from Microsoft.Xrm.Tooling.Connector nuget

 private CrmServiceClient GenerateService()     
    {            
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;            
        ServicePointManager.Expect100Continue = true;              
        ServicePointManager.CheckCertificateRevocationList = true;            
        ServicePointManager.DefaultConnectionLimit = 10; 
        var service = new CrmServiceClient(new Uri(organizationUrl), clientId, secret, false, string.Empty);
        if (service.IsReady == false)
        {
            throw new Exception("CrmOrgService isn't ready. " + service.LastCrmError);
        }
        return service;
    }

Or if you want to use connection string you can use this:

Connection string : https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/xrm-tooling/use-connection-strings-xrm-tooling-connect

        var connectionString = 
            ConfigurationManager.ConnectionStrings["XY"].ConnectionString;

        var conn = new CrmServiceClient(connectionString);
        IOrganizationService orgService = conn.OrganizationServiceProxy;