【问题标题】:How to authenticate with Google Service Account credentials using Postman and HTTPS?Postman 和 Google Service Account,如何授权?
【发布时间】:2019-08-07 21:41:45
【问题描述】:

我已阅读此文档

https://cloud.google.com/docs/authentication/getting-started?hl=ru#auth-cloud-implicit-java

https://cloud.google.com/storage/docs/reference/libraries?hl=ru

https://cloud.google.com/docs/authentication/production?hl=ru#obtaining_and_providing_service_account_credentials_manually

https://developers.google.com/identity/protocols/OAuth2ServiceAccount#callinganapi

(我已经获得服务帐户的 .json 凭据)

而且不聪明 关于获取身份验证令牌或 api 密钥的凭据的地址请求

只有图书馆。 所以凭证以某种方式授权,但是如何使用 HTTPS?

【问题讨论】:

    标签: google-api google-cloud-storage storage service-accounts


    【解决方案1】:

    找到了。

    在 JWT.io 上使用 RS256 签名

    标题:

    {
      "alg": "RS256",
      "typ": "JWT",
      "kid": "your_private_key_id"
    }
    

    有效负载:

    {
      "iss": "your_client_email_of_service_account",
      "sub": "your_client_email_of_service_account",
      "aud": "https://www.googleapis.com/oauth2/v4/token",
      "scope": "https://www.googleapis.com/auth/devstorage.read_only",
      "iat": current_unix_time,
      "exp": current_unix_time+3600
    }
    

    验证签名

    your_private_key 在最后一个字段中(不带 \n)

    得到编码的密钥

    然后

    POST /oauth2/v4/token HTTP/1.1
    
    Host: www.googleapis.com
    
    Content-Type: application/x-www-form-urlencoded
    
    Cache-Control: no-cache
    
    grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=ENCODED_KEY_FROM_JWT.IO
    

    我得到了回应

    {
    
        "access_token": "ya21.c.ElrSBodwuWANeh7Q0-zlXpOxqm9-uEszPElsY2tvoG5aPxRgOkasN5G2sMgj3iosPVbRYk1wXw_DcBnm2FtuNBlZpv_wCC0YS5pWMykR8Ouf5CZg-8OK842rvfk",
    
        "expires_in": 3600,
    
        "token_type": "Bearer"
    
    }
    

    也不要忘记为您的服务帐户授予权限以在存储中读取

    【讨论】:

    • 我想了解更多关于您如何使用 Jwt.io 创建令牌的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2021-05-14
    • 2020-05-05
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    相关资源
    最近更新 更多