0

I'm trying to get a pure command line oauth flow for an installed app and it's not easy to piece this together... Docs are sorely lacking... I started with the drive example (https://github.com/google/google-api-ruby-client-samples/tree/master/drive) but when it gets to client.authorization = flow.authorize(file_storage) it tries to start webrick to put up a web page. I need something that works similarly to the CLI tools provided by google: it needs to print out the URL I need to visit and then read in the response that I can copy&paste. Is this possible with the google ruby client?

1 Answer 1

1

Looks like the following monkey-patch works:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.