dongshen3352 2019-09-20 20:32
浏览 96
已采纳

如何在不将凭据存储在本地的情况下建立google oAuth客户端?

I'm trying to establish a google oAuth2 client with golang.org/x/oauth2/google so that I can schedule some email reminders for myself. If I understand the documentation correctly, the rough process goes like this.

  1. Get an oauth2.Config instance
  2. Use the config to get a token from google
  3. Use token to establish a client

The trouble I'm having is that all of the functions for generating config with golang.org/x/oauth2/google seem to require a local credential file from which to read what I assume are Google API Client id and Client secrets.

That's fine for a persistent runtime but this application will be running in a volatile location without a disk. I feel like I must be missing some obvious way to create the config using my api client id and secret that I have stored in the environment. Am I using this package incorrectly? How can I create an instance of oauth2.Config without having a local file?

  • 写回答

1条回答 默认 最新

  • dtp0760 2019-09-20 23:06
    关注

    I can think of a couple of things you can do:

    1) There is a ConfigFromJSON function that gets a JSON document as []byte. You can figure out what that file looks like, and generate it using the environment variables.

    2) It looks like all the package does is to prepare an oauth2 config. You can prepare the config yourself with the credentials you have, bypassing the library completely.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度