3CX oauth2 issue, getting a URL not found

Status
Not open for further replies.

greychain

Gold Partner
Advanced Certified
Joined
Jul 13, 2018
Messages
779
Reaction score
122
Getting this result. The screen that shows this error is from my pbx:

https://mypbx.mydomain.net:5001/api...NF1TAM..............&state=57d16c7b-df2b-42da..................

What could be causing this?


Error occured while accessing CRM. Please check log provided.
Started OAuthGetRefreshToken
Request text: https://mycrm.net/restapi/1.0/common/oauth2/access_token
Request form value code set to vC44SmHVtShNF1T......
Request form value grant_type set to authorization_code
Request form value client_id set to 9j87ZGMlJseKlFUacj......
Request form value client_secret set to Bg2HHO4fFQyPc......
Request form value redirect_uri set to https://mypbx.mydomain.net:5001/api/oauth2crm <-- This value is set in the CRM
Request form value state set to 57d16c7b-df2b-42da-93a7-............
System.Exception: Server returned a non successful status code - HTTPStatusCode=NotFound - Reason=NOT FOUND - Content=

Not Found​


The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.



at Integration.Crm.Engine.ScenarioProcessorBase.ProcessRequest(ScenarioRequest request, IValueManager customManager, HttpClient client, CancellationToken token)
at Integration.Crm.Engine.ScenarioProcessorBase.ProcessScenario(ProtocolScenario scenario, IValueManager customManager, CancellationToken token)
at Integration.Crm.Engine.ScenarioProcessorBase.Execute(ProtocolScenario scenario, CancellationToken token)
at Integration.Crm.Engine.CrmProcessor.ExecuteScenarioByName(String scenarioName, IEnumerable`1 parameters, Boolean useNoAuthProvider, CancellationToken token)
at ManagementConsoleJS.Controllers.OAuth2CrmController.OAuth(String state, CrmProcessorFactoryDelegate crmProcessorFactory, IMemoryCache cache)
 
Are you getting this error while trying to Authorize?
 
  • Like
Reactions: edossantos
The OAuth2 authorization flow works as follows:
1) 3CX launches the authorization endpoint in a new browser tab. This is the URL in your CRM, in which you grant access.
2) You grant access to 3CX from your CRM, and then the CRM sends the authorization code to 3CX.
3) 3CX then tries to invoke the endpoint to get a Refresh Token, by passing the authorization code. This is what's causing the error, because when 3CX invokes this endpoint (from your logs it's the URL https://mycrm.net/restapi/1.0/common/oauth2/access_token), the server returns a 404 Not Found error. Most probably this URL is incorrect.
 
Thanks for the explanation of the oauth2 flow. I'll test with postman
 
Are you getting this error while trying to Authorize?
Yes, when trying to do it in postman using {{host}}/restapi/1.0/common/oauth2/authorize?client_id={{client_id}}&redirect_url={{redirect_uri}}&response_type=code i get a 404 error. Do I need the $response_type=code?

If I set postman to use the Authorize using browser option I get
Your call is authenticated response on the postman webpage so I'm guessing it is the call back url which in my case is https://mypbx.net:5001/api/oauth2crm

if I use the redirect_url in a browser I get a 401 error. Do you have an example of a valid redirect_url with the required variables
 
Last edited:
Your problem is with the access_token endpoint, not with the authorization. Check my previous response. You will need to verify this with the documentation of the CRM you're trying to integrate....
 
So the first part is this

restapi/1.0/common/oauth2/authorize?client_id=9j87ZGMlJseKlFUacjJXY1l3Ts89Floi&redirect_uri=https://mypbx:5001/api/oauth2crm&response_type=code

Which returns this if I open a webpage using the above url:

:5001/api/oauth2crm?code=ngyZZHCnYnflMkRKS0AqkGtt36qjgMZN&state=None

In the CRM integration tool there is no response tree

but also a webpage that says this:

Error occured: State invalid or expired

How can I get the code value?

I then use:

restapi/1.0/common/oauth2/access_token?code=ngyZZHCnYnflMkRKS0AqkGtt36qjgMZN&client_id=9j87ZGMlJseKlFUacjJXY1l3Ts89Floi&client_secret=Bg2HHO4fFQyPclD4aYTlOfljsh3cuch0&$redirect_uri=https://mypbx:5001/api/oauth2crm&grant_type=authorization_code

Which returns this:

{"access_token": "A7piyGLGGIXfUp5OnlCVyvBQLdgdC2uG", "access_token_validity": 1800, "token_type": "Bearer", "refresh_token": "brKoTLqOofqxBTPkZDOzvdiL8V9Rkv0g"}
 
If you invoke the Redirect URL directly, without 3CX starting the authorization flow, 3CX will not recognize the value of the state argument you're passing...

If the endpoint restapi/1.0/common/oauth2/access_token is working now and returns an access token when you invoke it from Postman, then it should work from 3CX too.... Can you retry and see if that was a temporary error on the CRM side in the past?
 
  • Like
Reactions: edossantos
If you invoke the Redirect URL directly, without 3CX starting the authorization flow, 3CX will not recognize the value of the state argument you're passing...

If the endpoint restapi/1.0/common/oauth2/access_token is working now and returns an access token when you invoke it from Postman, then it should work from 3CX too.... Can you retry and see if that was a temporary error on the CRM side in the past?
If I use this code in a browser I get a code , if I use the same in postman as a hard coded get I get a 404 and the same if I do it as a php curl statement. If I copy the get command shown below and paste it into a browser I get the code.1695331812763.png

I haven't been able to get any successful results in Postman, even authorize
Could it be the $ ? It is there in what you say you use and works but not in the first URL.
Just using a un-fixed version stored in notepad, so a bit of a typo

"
If you invoke the Redirect URL directly, without 3CX starting the authorization flow, 3CX will not recognize the value of the state argument you're passing..."
When I am using the 3Cx CRM application does this fully emulate 3CX PBX?
 
  • Like
Reactions: Evolute IT
If I use this code in a browser I get a code , if I use the same in postman as a hard coded get I get a 404 and the same if I do it as a php curl statement. If I copy the get command shown below and paste it into a browser I get the code.
The browser performs a GET request. And most probably 3CX will perform a POST request as that's the standard to get a refresh token in OAuth2. Maybe your CRM is implementing a different variant and you will need to adjust the requests accordingly...

When I am using the 3Cx CRM application does this fully emulate 3CX PBX?
Yes, it uses the same DLL to execute the logic of the template....
 
  • Like
Reactions: Evolute IT
Status
Not open for further replies.

Forum statistics

Threads
112,322
Messages
591,882
Members
165,467
Latest member
EMMEPICASA