Sha256: f1cdd49fd8f241ec0cda49a34ebd7716ad2ab655552c7a9fc372bc83d1a5ce9d

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

require 'thor'
require 'drive_env'

module DriveEnv
  module Cli
    class Auth < Thor
      OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'

      desc 'login', ''
      def login
        if !config.client_id
          abort "please set client_id: #{$0} config set client_id YOUR_CLIENT_ID"
        end
        if !config.client_secret
          abort "please set client_secret: #{$0} config set client_secret YOUR_CLIENT_SECRET"
        end
        print("1. Open this page:\n%s\n\n" % authorizer.get_authorization_url(base_url: OOB_URI))
        print("2. Enter the authorization code shown in the page: ")

        code = $stdin.gets.chomp
        authorizer.get_and_store_credentials_from_code(user_id: DriveEnv::Config::DEFAULT_TOKEN_USER_ID, code: code, base_url: OOB_URI)
      end

      no_commands do
        def config
          @config ||= DriveEnv::Config.load(options[:config])
        end

        def authorizer
          DriveEnv.authorizer(config.client_id, config.client_secret, DriveEnv::Config::DEFAULT_TOKENS_STORE_FILE)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
drive_env-0.4.2 lib/drive_env/cli/auth.rb
drive_env-0.4.1 lib/drive_env/cli/auth.rb
drive_env-0.4.0 lib/drive_env/cli/auth.rb
drive_env-0.3.1 lib/drive_env/cli/auth.rb
drive_env-0.3.0 lib/drive_env/cli/auth.rb
drive_env-0.2.2 lib/drive_env/cli/auth.rb
drive_env-0.2.1 lib/drive_env/cli/auth.rb
drive_env-0.2.0 lib/drive_env/cli/auth.rb
drive_env-0.2.pre1 lib/drive_env/cli/auth.rb