【问题标题】:is there a pure command-line oauth flow for installed apps?已安装的应用程序是否有纯命令行 oauth 流程?
【发布时间】:2014-09-05 22:19:10
【问题描述】:

我正在尝试为已安装的应用程序获取纯命令行 oauth 流,但将其拼凑起来并不容易……文档非常缺乏……我从驱动器示例 (https://github.com/google/google-api-ruby-client-samples/tree/master/drive) 开始,但是当它到达client.authorization = flow.authorize(file_storage) 它试图启动 webrick 来建立一个网页。我需要与 google 提供的 CLI 工具类似的东西:它需要打印出我需要访问的 URL,然后读取我可以复制和粘贴的响应。 google ruby​​ 客户端可以做到这一点吗?

【问题讨论】:

    标签: google-api-ruby-client


    【解决方案1】:

    看起来像下面的猴子补丁工作:

    module Google
      class APIClient
        class InstalledAppFlow
          def authorize_cli(storage)
            puts "Please visit: #{@authorization.authorization_uri.to_s}"
            printf "Enter the code: code="
            code = gets
            @authorization.code = code
            @authorization.fetch_access_token!
            if @authorization.access_token
              if storage.respond_to?(:write_credentials)
                storage.write_credentials(@authorization)
              end
              @authorization
            else
              nil
            end
          end
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2016-05-11
      • 1970-01-01
      • 2015-09-25
      • 2011-02-03
      • 2014-09-04
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多