AlexaCRM / dynamics-webapi-toolkit

Dynamics 365 Web API Toolkit for PHP
MIT License
75 stars 58 forks source link

Integration help #83

Closed sotnaspina closed 8 months ago

sotnaspina commented 2 years ago

Hello, I'm having trouble integrating Dynamics 365 Sales and came here to ask for help. I'll explain how the integration should work... I have an area in my system where each customer logs in via Microsoft Azure and the Access Token is returned, after that use the api (AlexaCRM/dynamics-webapi-toolkit) to register the contacts in each account (access token returned). I've already done the entire process of creating the Application via Azure Active Directory for the customer to be able to login, I need to know if I can pass this Access Token received after Microsoft Azure login. I don't know if my question was clear.

georged commented 2 years ago

@sotnaspina

I'm not quite sure what are you trying to do. Are you trying to implement on-behalf-of authentication where your web app will access Dataverse as if it were a currently logged in user? We didn't implement that yet (see #6 discussion) but middleware is all there for you to plug your code in.

sotnaspina commented 2 years ago

Thanks, @georged.

Another problem I'm having is that I couldn't find where I can get the link to the dynamics crm instance, for example: https://[client's company].crm.dynamics.com.

This instance, would it be the link of my company or the company of each of my clients?

Thanks!!

georged commented 2 years ago

@sotnaspina

I still don't understand what you're trying to do. Do the clients have their own instances, i.e. you're creating a tool that can be used against multiple CRM instances? Or do you want to authorize them in your Azure AD and grant access to your instance?

As far as the instance URL is concerned, given that user is signed in, you can use discovery service.

sotnaspina commented 2 years ago

@georged

Let me try to explain in steps, maybe it helps to understand: 1 - in my system each client of mine has their contacts 2 - I have an area in the system where each customer clicks a button to login via Azure and get the access_token of the account 3 - I think that with this I would be able to use each customer's account to be able to register the contacts in Dynamics CRM for each customer 4 - and my company's (main) Azure account would only be used to create the App for each customer to be able to log in and I could get the token from it

Note: I don't know if the access_token part would be that. I don't know if the correct flow would be this.

sotnaspina commented 2 years ago

@georged

another thing is that I don't understand how this instance https://[...].crm.dynamics.com works? Every client of mine would have theirs??

georged commented 2 years ago

@sotnaspina

I'm still confused. 1 - "in my system". What is your system? A Dynamics 365/CRM instance? 3 - "register the contacts". What do you mean by "register"? Manage their contacts in your Dynamics CRM instance? 4- "create the app for each customer" - why do you need an app per customer if functionality is the same?

another thing is that I don't understand how this instance https://[...].crm.dynamics.com works? Every client of mine would have theirs??

I don't know what your requirements are. Do you need an instance per client?! Does not sound like you do. And in any case, it sounds your clients wouldn't access this instance directly or be aware of it - why do they need to know?

If you need this toolkit it means you're building PHP pages that talk to Dynamics. Do you? And your clients sign in on these pages using Azure AD? And you need to access Dynamics 365 from these pages and allow your clients to modify contact list of theirs?

sotnaspina commented 2 years ago

@georged

If you need this toolkit it means you're building PHP pages that talk to Dynamics. Do you? And your clients sign in on these pages using Azure AD? And you need to access Dynamics 365 from these pages and allow your clients to modify contact list of theirs?

Yes, I need to communicate with Dynamics 365 CRM, so I need each client's access_token so I can register/modify the client's contacts (I don't know if via access token would be the only way to do it). I don't know if this library is prepared for this kind of integration.

georged commented 2 years ago

To communicate with Dynamics 365 you don't need each client's access_token unless you're impersonating. What you need is server-to-server which we support. When your clients sign in, you get a claim that contains email address. Using that you can find client's record in CRM and then related contacts.

sotnaspina commented 2 years ago

@georged

To communicate with Dynamics 365 you don't need each client's access_token unless you're impersonating.

That's it, I'm going to do the communication on behalf of the customer, but I need the access_token (I'm not sure if it's the only way) to register/modify the contacts directly in the Dynamics 365 CRM account of each customer. I think we are now coming to an understanding and correct terms.

I really appreciate your patience and the enormous help you are giving me.

georged commented 2 years ago

@sotnaspina I'm afraid we still talking about different things

There are two possible scenarios:

  1. Your customers are CRM users and have a license. Then you can use on-behalf-of and impersonate individual customer. We do not have code for this scenario but feel free to add your own.
  2. Your customers are CRM accounts and need to login to modify their contacts. You don't need impersonation, you simply access CRM using single app account and then modify contacts using account id that is known at this stage via original login. We support this scenario.
sotnaspina commented 2 years ago

@georged

It seems to me that it is scenario 2, each client of mine has a CRM and each one logs in through my app created in Azure Active Directory (so I can link the CRM client with the client in my system), with that I need to get the identification (from your CRM) to be able to register/modify the contacts in the CRM.