【问题标题】:Php equivalent for gcloud auth print-identity-token相当于 gcloud auth print-identity-token 的 PHP
【发布时间】:2021-12-30 14:05:27
【问题描述】:

我的目标是通过我的 php 代码触发谷歌云功能。为此,我需要一个身份令牌作为承载,但我的服务器上没有安装 gcloud。 我有一个工作服务帐户,并通过 Google_Client 创建了一个对象(“google/apiclient”:“2.10.1”):

$this->setAuthConfig($serviceJson);
$scope = [Google_Service_Compute::CLOUD_PLATFORM, 'openid', 'email'];
$this->addScope($scope);
if ($this->isAccessTokenExpired()) {
  $this->fetchAccessTokenWithAssertion();
}
$this->getAccessToken()

使用此客户端,我只能获取 access_token(未授权触发云功能),但 id_token 始终为空。

如何获取 id_token?是否有可以提供帮助的 php 库,或者我是否需要执行单独的 POST 请求来获取 id_token?

【问题讨论】:

    标签: php google-cloud-platform google-cloud-functions gcloud


    【解决方案1】:

    我找到的唯一方法是这样的:

    1. 生成JWT manually(根据服务帐户中的数据)
    2. 将其发送至https://www.googleapis.com/oauth2/v4/token 并接收令牌
    3. 在 CF 调用中使用令牌

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-08
    • 2017-08-25
    • 2022-06-29
    • 1970-01-01
    • 2015-04-28
    • 2019-04-17
    • 1970-01-01
    相关资源
    最近更新 更多