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

Add refresh callback to CLI #31

Open
brad opened this issue Nov 28, 2018 · 6 comments
Open

Add refresh callback to CLI #31

brad opened this issue Nov 28, 2018 · 6 comments

Comments

@brad
Copy link
Member

brad commented Nov 28, 2018

Setup a refresh callback for the CLI, will fix #30

@ethanopp
Copy link

ethanopp commented Jun 27, 2019

@brad Any update on this? Still confused how refresh and save tokens, to then use those saved tokens for the next api request.

@brad
Copy link
Member Author

brad commented Jun 27, 2019

Sorry @ethanopp at this point this is not a needed feature for the product owner so it will not happen unless a community member contributes the code

@ethanopp
Copy link

Didn’t someone already do this?

#33

@brad
Copy link
Member Author

brad commented Jun 27, 2019

@ethanopp The method in that PR manually refreshes tokens and doesn't save them for later (just updates the tokens for use in the current session)

A refresh callback is a method that takes a new token (automatically generated by oauthlib) as input and persists it somewhere (in this case, it should be a config file).
Here is an example, but in that case the token is saved to the DB. Then when you create a NokiaApi you simply pass that method to the constructor and the rest is magic

@ethanopp
Copy link

@brad forgive me if I'm missing something here (a little new to developing with oauth 2), but what is the purpose of saving the creds then if you're never using them to make a request?

My understanding with the other apps I've used oauth2 on was that you save the creds, and then in the application do something like the following, so you're only gettting new tokens once the ones you saved have expired:

# Main code here where you pull current tokens for specific user from db and give to client()...then:

if time.time() > client.token_expires_at:
    refresh_response = client.refresh_access_token(client_id=1234, client_secret='asdf1234',
        refresh_token=client.refresh_token)

    # Code here to write new tokens to db for that user

    # Update current session with the new tokens
    client.access_token = refresh_response['access_token']
    client.refresh_token = refresh_response['refresh_token']

@ethanopp
Copy link

Dug through the code a little bit and think I found what I was looking for...

client = NokiaApi(creds, refresh_cb=save_withings_token)

Where save_withings_token is my method to save creds to db

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

2 participants