Google OAuth 工作流程 - Safari

发布时间:2021-03-07 16:39
    如果默认浏览器是 Safari,则
  • run_flow() 不起作用。 MacOS 10.16.7,Safari 14.0.2。这是预期的吗?
  • 有没有办法让 run_flow() 使用 Chrome

Python 代码改编自示例谷歌代码

        credential_dir = Path.home().joinpath('.credentials')
        if not credential_dir.exists(): credential_dir.mkdir()

        store = Storage(credential_dir.joinpath(f'{appname}.json'))
        credentials = store.get()
        if not credentials or credentials.invalid:
            cs = [p for p in Path.cwd().glob("**/client*.json")][0]
            flow = client.flow_from_clientsecrets(cs, SCOPES)
            flow.user_agent = appname
            # NB this fails with Safari, set Chrome as default for this to work
            credentials = tools.run_flow(flow, store, None)
        return credentials
回答1