question

Lisa Xu avatar image
Lisa Xu asked Phong Vu commented

Error: Refresh token is invalid because it was issued for a different application

In a background app i am able to use saved token string to get attachment info, but when i try to use refresh token for some bigger file i got error message:

Content: {
                 
  "error" : "invalid_grant",
  "errors" : [ {
                 
    "errorCode" : "OAU-202",
    "message" : "Refresh token is invalid because it was issued for a different application"
} ],
  "error_description" : "Refresh token is invalid because it was issued for a different application"
}

Request:

Method: POST, RequestUri: 'https://platform.devtest.ringcentral.com/restapi/oauth/token', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:

{
                 
  X-User-Agent: Unknown/0.0.1 RingCentral.Net/5.2.0
  Authorization: Basic aEJXMElab3lRc1dPcDVjdWgwYXN0UTpCak1BcnJnWVNkeVMyWkJIbzNnUmlBZk1vZjFZTG1SU3FRUU41YUVTN21LQQ==
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 369
}

The code i am using like following:

 rc.token = JsonConvert.DeserializeObject<TokenInfo>(tokenString);

 try
 {
                 
   TestRefresh(tokenString).Wait();
 }
   catch (Exception ex)
 {
                 
   var s = ex.Message;
 }
 Authorized = true;

 public async Task TestRefresh(string tokenString)
 {
                 
   var token = JsonConvert.DeserializeObject<TokenInfo>(tokenString);

   token = await rc.Authorize(new GetTokenRequest
   {
                 
     grant_type = "refresh_token",
     refresh_token = token.refresh_token,
     access_token_ttl = 1800,
     refresh_token_ttl = 302400
   });
   rc.token = token;
 }


TestRefresh always failed, how to make refresh work?

Thanks.

notifications
1 |3000

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

Phong Vu avatar image
Phong Vu answered

Did you generate the tokens and call get refresh token using the same app client id?

Check you `rc` instance

var rc = new RestClient("APP_CLIENTID", "RINGCENTRAL_CLIENTSECRET", true);

I am not sure where did you get the syntax rc.Authorize(new GetTokenRequest ...), but here is how to save and reuse tokes using the RingCentral .NET SDK

static TokenInfo tokens = null;
...
RestClient rc = new RestClient("APP_CLIENTID", "RINGCENTRAL_CLIENTSECRET", true);
if (tokens == null)
{
    Console.WriteLine("get new tokens");
    await rc.Authorize(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD);
    tokens = rc.token;
}
else
{
    Console.WriteLine("reuse tokens");
    rc.token = tokens;
}
// call any API
var parameters = new ListMessagesParameters();
parameters.messageType = new string[] { "SMS" };

var response = await rc.Restapi().Account().Extension().MessageStore().List(parameters);
var jsonStr = JsonConvert.SerializeObject(response);
Console.WriteLine(jsonStr);
1 |3000

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

Lisa Xu avatar image
Lisa Xu answered Phong Vu commented

i do use same app client id, actually there is not other client id to use.

your example there is not any code related refresh token.

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.

Just call rc.refresh() after setting back the tokens

0 Likes 0 ·