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

Way to set onCredentialsRefreshed #171

Open
oliver92 opened this issue Feb 26, 2020 · 3 comments
Open

Way to set onCredentialsRefreshed #171

oliver92 opened this issue Feb 26, 2020 · 3 comments

Comments

@oliver92
Copy link

Could you please put a way to set the onCredentialsRefreshed in the AuthorizationCodeGrant so a top level notification is sent that the refresh token has been refreshed. I need this because when i use the installed flow, once i authorize i store the credentials so i can use the restore flow. But since i never update the credentials stored, after the expiration of the refresh token, DRAW refreshes it, but i never update my credentials. So then when the application is closed and then opened after a while the restore method fails since i give it the old refresh token.

Also i noticed the friend and unfriend return error "$username is not a know Redditor". I can open a separate issue for this, if thats what your prefer.

Tnx for the awesome API wrapper BTW :)
Oliver

@bkonyi
Copy link
Member

bkonyi commented Apr 13, 2020

Sorry for the delay, I'll investigate this.

If you could file a separate issue for the friend/unfriend error you're seeing, that would be great. Thanks!

@inhumantsar
Copy link

I'm affected by this as well.. as a workaround, i refresh the token on every call to the Reddit obj and store it if it differs. i don't know if this a good workaround but it's working so far.

  Reddit get reddit {
    this.refreshCredentials();
    return this._reddit;
  }

  void refreshCredentials() {
    this._reddit.auth.refresh();
    newCredentials = this._reddit.auth.credentials.toJson();
    if (newCredentials != getStoredCredentials) {
      storeCredentials(newCredentials);
    }
  }

@SupremeDeity
Copy link
Contributor

SupremeDeity commented Aug 10, 2021

A summary of whatever is below:
Access Token: Expires after 1 hour of issuance.
Refresh Token: Can be used to get a access token indefinitely. Expires 1 year after last usage. Use restoreInstalledFlow() with this.

A more detailed version:
@bkonyi You need to decide whether or not the implicit flow is needed. I personally think its not needed for reddit.

We don't need a for onCredentialsRefreshed.

First Method(Not implemented):
Currently the implicit parameter is not passed and the implicit authorization type is not used. This type is ONLY for Installed applications. No refresh token is returned, and the access code expires every 1 hour. It also returns the time when the code will expire, using which you can know if the code expired.

Second Method:
By default with the installed flow, if you don't change the duration parameter on Reddit.auth.url() (its permanent by default), you will get a refresh token which expires 1 year after last use. Meaning as long the token is in continuous use, you can indefinitely use Reddit.restoreInstalledAuthenticatedInstance(). So just save the last used time, and generate a new one if its been a 1 year after the last Reddit.restoreInstalledAuthenticatedInstance() use.

Secondly, if you decide to use temporary duration, you wont get a refresh token. You only get a access token which expires after 1 hour. Either get a new token every time the app opens up or save the time when the code was used. Check the time and then do the auth again.

Also look at #196.

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

No branches or pull requests

4 participants