question

mahesh-more3143 avatar image
mahesh-more3143 asked Anirban edited

Invalid client error while calling refresh token api

Hi All,


I am calling refresh token api to refresh token. But when I call, It throws error "Invalid client: ".

I am calling using node js.Below is calling function.


request.post( { url : ringCentralUrl,

form: {

refresh_token : myRefreshToken,

grant_type : "refresh_token",

endpoint_id: endpointId

},

headers:{


"Authorization" : "Basic MyaccessToken",

'Accept':'application/json',

'Content-Type':'application/x-www-form-urlencoded'

}

},function(err,responce, responceData) {




});


Can anyone please help me out.



----

Thanks,

Mahesh More

errors
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered
It probably means your appKey or appSecret is wrong.

In your code there is "MyaccessToken", how did you generate it?
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

mahesh-more3143 avatar image
mahesh-more3143 answered Tyler Liu commented
Hello Tyler,

MyaccessToken I have generated using RingCentral OAuth 2.0 Authentication.

Do you mean I am using wrong appKey or appSecret while generating access token ?

Thanks,
---
Regards,
Mahesh More



3 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

mahesh-more3143 avatar image mahesh-more3143 commented ·
Also I am able to call RingCentral Api using access token. Only I face this problem while refreshing access token.
0 Likes 0 ·
Tyler Liu avatar image Tyler Liu ♦ commented ·
Are you using this:  https://github.com/ringcentral/ringcentral-js ?  If so, there is already 'refresh' method and you don't have to implement your own:  https://github.com/ringcentral/ringcentral-js/blob/master/src/platform/Platform.js#L375

If you still prefer to implement it yourself, Pay attention to "MyaccessToken". It should NOT be OAuth 2.0 accessToken.  Here is code sample for how to generate it:  https://github.com/ringcentral/ringcentral-csharp/blob/master/RingCentral/Platform/Platform.cs#L178  It's C# but you can get the idea: it's not OAuth 2.0 accessToken, it's generated by appKey and appSecret directly.
0 Likes 0 ·
Tyler Liu avatar image Tyler Liu ♦ commented ·
There are two types of tokens: the bearer token and the basic token. You are using the bearer token as the basic token that's why it doesn't work.
0 Likes 0 ·
benjamin-dean avatar image
benjamin-dean answered
Could you please provide the following:

1. Are you using the RingCentral JS SDK? If yes, which version?
2. Description of the 'endpointId' variable's assigned value
3. The complete error response with headers/body from this request

This will help in figuring out what is happening here.
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

mahesh-more3143 avatar image
mahesh-more3143 answered
I am not using SDK.
I have entered endpointId value which I got it with access token.

Below is the error I am facing.

 {
  "error" : "invalid_client",
  "error_description" : "Authentication header value is malformed"
}



Please do let me know if you need more information.


1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

benjamin-dean avatar image
benjamin-dean answered
You will need to view the documentation, because Tyler is correct, you are using the incorrect Authorization Header key:value.  https://developers.ringcentral.com/api-docs/latest/index.html#!#RefRefreshTokenFlow

What this means is in your example you set the "Authorization: Basic { {myAccessToken}}", but this is incorrect because you SHOULD NOT be using your "access_token" as this value, you should instead be using the result of Base64 encoding your { {appKey}}:{ {appSecret}} (which is the same value you used to obtain the 'access_token' initially).

Also, please pay special attention to the description for endpointId...
If not specified, the previously specified or auto-generated value is used by default
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

sahiba-singh8943 avatar image
sahiba-singh8943 answered Tyler Liu commented
Mahesh More,have you get the solution.Have you get the solution to refresh the access token?
If yes please share code.Thanks
1 comment
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image Tyler Liu ♦ commented ·
If you use the official SDKs, there are refresh methods to invoke. If you tell me you programming language, I can send you some sample code.
1 Like 1 ·
Anirban avatar image
Anirban answered Anirban edited

Yes you don't need to put access_token in Authorization header. All you need to put is Base64 format of clientId and client secret as follow:

Authorization Basic <clientId:clientSecret in Base64>

Access_token are need to pass to the actual main APIs as type Bearer to get the response

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys