Getting "invalid_grant" while navigation on SugarCRM

Hi.

I browse SugarCRM inside several iFrames in my Web Application. The SessionID is always the same.

When I log in SugarCRM I can see a "/rest/v10/oauth2/token" with my credentials and I get the following reply:

{"access_token":"tokenAccess","expires_in":3600,"token_type":"bearer","scope":null,"refresh_token":"tokenRefresh","refresh_expires_in":1209600,"download_token":"tokenDownload"}

After some minutes, while navigating, I'm redirected to the login page. When that happens I see the following request to "/rest/v10/oauth2/token":

{"grant_type":"refresh_token","client_id":"sugar","client_secret":"","refresh_token":"refreshToken","platform":"base","refresh":true}

But I get the response:

{"error":"invalid_grant","error_message":"Invalid refresh token"}

Inside SugarCRM I have some custom code that invokes WebServices on my side. That WebServices requests tokens to SugarCRM with a different user that is navigating BUT in some cases I invoke "/rest/v10/oauth2/sudo/ with the user that is navigating.

Anyone have an idea of why the "Invalid refresh token"?

Thanks in advance.

 

Parents
  • Hi Nuno,

    It isn't that much easy to identify this kind of problems. Can you try to disable your custom code to see if that changes this behaviour? 

    Best Regards
    Tevfik Tümer
    Developer Support Engineer

  • Hi,

    I've commented the code I was suspecting and the problem seems to disappear.

    I wonder if anyone has a suggestion to solve this issue.

    Here is what I do:

    • I'm calling oauth2/token with a special API user to obtain a token
    • I use this token is every REST call
    • There is one place where I need to add a "Call". I need this "Call" to be associated with the user navigating in SugarCRM and not to the "special API user". Therefore, I'm:
      • Calling oauth2/sudo/<navigatingUser> with the oath-token header of the special API user
      • Calling /Calls with the oauth-token header set with the token fetched on the last step.

    This seems to ruin my navigation session.

    Any hint?

    Thanks

Reply
  • Hi,

    I've commented the code I was suspecting and the problem seems to disappear.

    I wonder if anyone has a suggestion to solve this issue.

    Here is what I do:

    • I'm calling oauth2/token with a special API user to obtain a token
    • I use this token is every REST call
    • There is one place where I need to add a "Call". I need this "Call" to be associated with the user navigating in SugarCRM and not to the "special API user". Therefore, I'm:
      • Calling oauth2/sudo/<navigatingUser> with the oath-token header of the special API user
      • Calling /Calls with the oauth-token header set with the token fetched on the last step.

    This seems to ruin my navigation session.

    Any hint?

    Thanks

Children