Merge pull request #1091 from dokime7/patch-8
Add renew token by using refresh_token
This commit is contained in:
@@ -139,24 +139,34 @@ server for requests. It can be used for the optional"scope" parameters for Face
|
|||||||
Return the access token generated by the authenticating server.
|
Return the access token generated by the authenticating server.
|
||||||
|
|
||||||
If token is already in the session that one will be used.
|
If token is already in the session that one will be used.
|
||||||
|
If token has expired refresh_token is used to get another token.
|
||||||
Otherwise the token is fetched from the auth server.
|
Otherwise the token is fetched from the auth server.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
refresh_token = None
|
||||||
if current.session.token and 'expires' in current.session.token:
|
if current.session.token and 'expires' in current.session.token:
|
||||||
expires = current.session.token['expires']
|
expires = current.session.token['expires']
|
||||||
# reuse token until expiration
|
# reuse token until expiration
|
||||||
if expires == 0 or expires > time.time():
|
if expires == 0 or expires > time.time():
|
||||||
return current.session.token['access_token']
|
return current.session.token['access_token']
|
||||||
|
if 'refresh_token' in current.session.token:
|
||||||
|
refresh_token = current.session.token['refresh_token']
|
||||||
|
|
||||||
code = current.request.vars.code
|
code = current.request.vars.code
|
||||||
|
|
||||||
if code:
|
if code or refresh_token:
|
||||||
data = dict(client_id=self.client_id,
|
data = dict(client_id=self.client_id)
|
||||||
client_secret=self.client_secret,
|
if code:
|
||||||
redirect_uri=current.session.redirect_uri,
|
data.update(
|
||||||
code=code,
|
client_secret=self.client_secret,
|
||||||
grant_type='authorization_code'
|
redirect_uri=current.session.redirect_uri,
|
||||||
)
|
code=code,
|
||||||
|
grant_type='authorization_code'
|
||||||
|
)
|
||||||
|
if refresh_token:
|
||||||
|
data.update(
|
||||||
|
refresh_token=refresh_token,
|
||||||
|
grant_type='refresh_token'
|
||||||
|
)
|
||||||
|
|
||||||
open_url = None
|
open_url = None
|
||||||
opener = self.__build_url_opener(self.token_url)
|
opener = self.__build_url_opener(self.token_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user