将OAuth2Session请求转换为google oauth2凭据

2024-04-18 23:14:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我构建了一个flask应用程序,授权用户使用^{}'s google blueprint

我想使用该用户的授权使用GCS Client访问地面军事系统

我如何转换一个 ^{}(由flask_dance返回) 到一个^{}(googlecloud libs所需要的),这将使这成为可能?你知道吗

OAuth2Session中的令牌如下所示:

{
    'id_token': 'eyJh....',
    'access_token': 'ya29.Glw....',
    'expires_at': 1561605616.261379,
    'expires_in': 3573.162272,
    'scope': [
        'https://www.googleapis.com/auth/userinfo.email',
        'openid',
        'https://www.googleapis.com/auth/cloud-platform',
        'https://www.googleapis.com/auth/userinfo.profile'
    ],
    'token_type': 'Bearer'
}

Tags: 用户httpscomclienttokenauth应用程序flask
1条回答
网友
1楼 · 发布于 2024-04-18 23:14:05

最简单的方法是提取访问令牌并使用它创建新凭据。你知道吗

// Grab the Access Token from the OAuth Flow
access_token = resp.json()["access_token"]

// Create new credentials with the Access Token
credentials = google.auth.credentials.Credentials(access_token)

注意:在OAuth流中,必须包含Google云存储范围。您需要修改make_google_blueprint以包含云存储的作用域。示例:

https://www.googleapis.com/auth/devstorage.read_only
https://www.googleapis.com/auth/devstorage.read_write
https://www.googleapis.com/auth/devstorage.full_control

相关问题 更多 >