Gre*_*reg 6 google-api-python-client
我有一个已被批准为openid和email范围的授权API客户端的应用程序。我仍然得到“您的域管理员已批准进入”闪屏作为记录在这里。解决方案是不通过access_type参数请求脱机访问。
我的授权流程是使用构建的flow_from_clientsecrets(),并且没有像OAuth2WebServerFlow这样的方法来传递访问类型作为参数。有没有一种方法可以指定应用程序不需要客户端库的刷新令牌?
我自己刚刚开始使用 Google API Python 客户端库,发现自己处于与您完全相同的情况。根据我的阅读,仅返回应用了一组基本参数的flow_from_clientsecrets()a 。Flow事实证明,创建自己的OAuth2WebServerFlow对象并应用您需要的任何额外参数要简单得多。
这是我在仔细研究 googleapiclient 和 oauth2client 库中的示例后拼凑出的解决方案:
# Returns a flow that will prompt for offline access, thus receiving
# a refresh_token in the auth object that gets returned
def prepare_flow(secrets_path, scope):
# Grab settings from the client_secrets.json file provided by Google
with open(secrets_path, 'r') as fp:
obj = json.load(fp)
# The secrets we need are in the 'web' node
secrets = obj['web']
# Return a Flow that requests a refresh_token
return OAuth2WebServerFlow(
client_id=secrets['client_id'],
client_secret=secrets['client_secret'],
scope=scope,
redirect_uri=secrets['redirect_uris'][0],
access_type='offline',
approval_prompt='force')
Run Code Online (Sandbox Code Playgroud)
您可以将替换的调用替换flow_from_clientsecrets为对上述函数的调用:
flow = prepare_flow(client_secrets, scope)
Run Code Online (Sandbox Code Playgroud)
我刚刚使用它运行了一次干净的身份验证Flow,并验证了从 Google 返回的身份验证有效负载中是否存在刷新令牌。
| 归档时间: |
|
| 查看次数: |
831 次 |
| 最近记录: |