robinhood-unofficial / pyrh

Python Framework to make trades with the unofficial Robinhood API
https://pyrh.readthedocs.io/en/latest/
MIT License
1.78k stars 604 forks source link

Refresh token #180

Closed anilshanbhag closed 5 years ago

anilshanbhag commented 5 years ago

176 solution works and I am able to login

Once you get the access token, how do you refresh the token after 24 hours ? I tried the following piece of code and it fails.

    def relogin_oauth2(self):
        '''
        (Re)login using the Oauth2 refresh token
        '''
        url = "https://api.robinhood.com/oauth2/token/"
        data = {
            "grant_type": "refresh_token",
            "refresh_token": self.refresh_token,
            "scope": "internal",
            "client_id": self.client_id,
            "expires_in": 86400,
        }
        print(data)
        res = self.session.post(url, data=data)
        print(res)
        res = res.json()
        self.access_token   = res["access_token"]
        self.refresh_token  = res["refresh_token"]
        self.mfa_code       = res["mfa_code"]
        self.scope          = res["scope"]
brianschardt commented 4 years ago

@anilshanbhag have you figured out how to refresh the token?

adithyabsk commented 4 years ago

@brianschardt on the mainline codebase, refreshing the tokens is implemented.

adithyabsk commented 4 years ago

And if you reset the session you just need to use the save and load of the credentialing as documented in the SessionManager.