CRM Integration with Mixed Authentication Types

Status
Not open for further replies.

sifs

Customer
Joined
Apr 16, 2021
Messages
2
Reaction score
0
Hi there,

I'm in the process of testing compatibility of the CRM Template Generator with a custom CRM we use. The roadblock i'm coming up against is that the API for this CRM is a little different and needs different types of authentication depending on the function being performed.

If I want to do a contact lookup with the CRM, it uses basic authentication through an ODATA service/request. (i've tested this and it works)

[ODataApiUrl]/Clients?$filter=HomePhone eq '[Number]' or WorkPhone eq '[Number]' or HomeMobile eq '[Number]'&$select=FirstName,LastName,HomePhone,WorkPhone,HomeMobile,HomeEmail

If I want to do any other function, like call journaling - I need to use OAuth type authentication to a REST endpoint.

Is there any way that I can mix the type of authentication the CRM template generator uses depending on the type of function it's going to perform? Are there any examples of this in the existing templates in 3cx that I can refer to for guidance?

Many thanks for any advice you have!
 
Last edited:
Hello @sifs,

I have never tried this, but just checked the details of how this is implemented, and it should be possible to do it. Let me explain what you need to do.

First, please note that both authentication mechanisms (Basic and OAuth2) use the Authorization header. So you will need to use a trick to get this done properly, selecting the right header value in the right moment.

Basic authentication uses static details. Then, in the scenarios in which you must use basic authentication, you can add the header to the request as follows:
XML:
<Request Url="YOUR_URL">
    <Headers>
        <Value Key="Authorization">Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==</Value>
    </Headers>
</Request>

Where QWxhZGRpbjpvcGVuIHNlc2FtZQ== is the UserName:Password, encoded in Base64 as explained here. Please note that the template doesn't provide any function to encode a string in base64, so you will need to provide that encoded string as a parameter. Users would need to use an online tool like this to get this base64 encoded value from their credentials.

Now the tricky part with OAuth2. You will see that the template generated with the wizard generates the Auth scenario with the following outputs:
XML:
<Outputs AllowEmpty="false">
    <Output Type="HeaderName" Value="Authorization"/>
    <Output Type="HeaderValue" Value="Bearer [AccessToken]"/>
    <Output Type="BearerExpiration" Value="[ExpiresIn]"/>
</Outputs>

This scenario is executed every time the CRM engine needs a new access token, and automatically sets the headers to use with every subsequent request. You must change this, to avoid providing the header value. Instead, you need to store the access token in an output, so it can be used later. So, the outputs for the Auth scenario should be the following instead:
XML:
<Outputs AllowEmpty="false">
    <Output Type="AccessToken" Value="[AccessToken]"/>
    <Output Type="BearerExpiration" Value="[ExpiresIn]"/>
</Outputs>

And then you can configure the requests that need OAuth2 authentication with the header as follows:
XML:
<Request Url="YOUR_URL">
    <Headers>
        <Value Key="Authorization">Bearer [AccessToken]</Value>
    </Headers>
</Request>

As I said, I never tried this, and I might be missing something, but you can give it a try and let us know if this works for you.

Kind regards.
 
Great reply @edossantos,

I'll give it a go when I have a moment and let you know if it works.

If this doesn't work, I figure my only other way to solve this one is to build a proxy between 3cx and our CRM to simplify the API/Authentication from 3CX's side. Hopefully I can avoid having to do that.

​

 
Yes, that would be another option, but I think it should work as I described it.
 
Status
Not open for further replies.

Latest Posts

Forum statistics

Threads
112,323
Messages
591,896
Members
165,474
Latest member
costionofrei