python - Google OAuth2 通过访问令牌获取刷新令牌
问题描述
我有这样的python授权:
def return_token():
return get_oauth2_token()
def disable_stout():
o_stdout = sys.stdout
o_file = open(os.devnull, 'w')
sys.stdout = o_file
return (o_stdout, o_file)
def enable_stout(o_stdout, o_file):
o_file.close()
sys.stdout = o_stdout
def get_oauth2_token():
CLIENT_ID = '123'
CLIENT_SECRET = '123'
SCOPE = \
'https://www.googleapis.com/auth/plus.login ' + \
'https://www.googleapis.com/auth/plus.me ' + \
'https://www.googleapis.com/auth/userinfo.email ' + \
'https://www.googleapis.com/auth/userinfo.profile ' + \
'https://mail.google.com/ ' + \
'https://www.googleapis.com/auth/gmail.readonly ' + \
'https://www.googleapis.com/auth/gmail.settings.basic'
REDIRECT_URI = 'http://localhost:8080'
o_stdout, o_file = disable_stout()
flow = OAuth2WebServerFlow(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope=SCOPE,
redirect_uri=REDIRECT_URI)
storage = Storage('creds.data')
credentials = run_flow(flow, storage)
enable_stout(o_stdout, o_file)
print("access_token: %s" % credentials.access_token)
print("refresh_token: %s" % credentials.refresh_token)
if __name__ == '__main__':
return_token()
此代码工作和授权返回访问和刷新令牌。只有当我拥有访问和刷新令牌时,我在后端的所有逻辑才会起作用。前端使用react-native-google-signin
库的开发人员和此库不返回刷新令牌。我有一个问题:我能refresh token
过access token
吗?
解决方案
推荐阅读
- ios - 获取Objective C对象的内存地址?
- python - 区间内的 Python 绘图函数
- javascript - 如何从 Google Picker API 中提取数据,以便使用 ReactJS 将其渲染到 DOM?
- plsqldeveloper - 在 PL/SQL Developer 的编辑器中删除代码文本的尾随空格
- blazor-server-side - Blazor 服务器组件未重新呈现
- sql - 在左连接中放置条件的背后是什么
- python-3.x - M1 Big sur 11.1 中的 numpy 构建失败
- php - Laravel 验证浮动
- python - 数据框:删除以特定字符串结尾的行?
- java - 如何计算sql中特定工作卡的开放作业和已关闭作业的数量?