Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Refresh token #40

Closed
ashitvora-zz opened this issue Aug 29, 2016 · 4 comments
Closed

Unable to Refresh token #40

ashitvora-zz opened this issue Aug 29, 2016 · 4 comments

Comments

@ashitvora-zz
Copy link

When I try to refresh the token, I get an error "Refresh Token has Expired".
After user authorized the app, I saved entire payload which had following info...

{
    "access_token": "*****",
    "token_type": "bearer",
    "expires_in": 3598,
    "refresh_token": *****",
    "refresh_token_expires_in": 604798,
    "scope": "ReadCallLog",
    "owner_id": "12345",
    "endpoint_id": "*****"
}

How can I have valid refresh token to call other apis?

@tylerlong
Copy link
Contributor

The refresh token was valid at the time you got it. But later it expired. You should always remember to refresh it before it expires.

By the way, if you refresh it successfully, a new refresh token is returned and the current one expires automatically, so please remember to save the latest payload every time you refresh the token.

@ashitvora-zz
Copy link
Author

So if user authenticates today and if I dont make any request for next 24 hrs, I have to ask user to authenticate again (since I can not use access token or refresh token to get new access token).

In that case, I can do nothing if user does not explicitly take any action.

Is it? Or am I missing something here?

@LingForCC
Copy link

LingForCC commented Aug 29, 2016

Yes. You are right. If user takes no actions, the refresh token will be expired in the end. You need to ask user to re-login. Another option is to refresh the token in regular time span explicitly in your application.

BTW, according to the payload you pasted above, refresh token will be expired in 7 days.

@tylerlong
Copy link
Contributor

In that case, I can do nothing if user does not explicitly take any action.

That's not true. You can setup a cron job to refresh the tokens. refresh_token expires in 7 days, so you need to run the cron job at least once per week.

And there is something tricky you should be aware of: https://github.com/ringcentral/ringcentral-php/blob/master/src/Platform/Platform.php#L237 According to the source code, sometimes the sdk refreshes the token for you. If this happens, you'd have to save the new payload because the old one just expires. I think this is the root cause of the issue you posted.

In the C# Client, there is a token refresh event so programers can easily save the latest payload taking advantages of the listener design pattern. But there isn't such thing in this PHP SDK. @anilkumarbp @kirill-konshin @grokify Please advise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants