Sha256: 0952c0a8f005c9d87b7bba5a98d7263c31c58e3b403f7b1fa1e9c1acde80e9c0

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'googleauth'
require 'googleauth/stores/file_token_store'

module Lt
  module Google
    module Api
      module Auth
        class Cli
          CONFIG_SECRET_FILE = Rails.root.join('config', 'google', 'client_secret.json')
          CONFIG_TOKEN_FILE  = Rails.root.join('config', 'google', 'app_token.yaml')
          SCOPE = %w(https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/documents).freeze
          USER_ID = 'default'

          def self.authorizer
            @authorizer ||= begin
              client_id = ::Google::Auth::ClientId.from_file(CONFIG_SECRET_FILE)
              token_store = ::Google::Auth::Stores::FileTokenStore.new(file: CONFIG_TOKEN_FILE)
              ::Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store)
            end
          end

          def authorizer
            self.class.authorizer
          end

          def credentials
            @credentials ||= authorizer.get_credentials(USER_ID)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lt-google-api-0.3.0 lib/lt/google/api/auth/cli.rb
lt-google-api-0.2.4 lib/lt/google/api/auth/cli.rb
lt-google-api-0.2.3 lib/lt/google/api/auth/cli.rb
lt-google-api-0.2.2 lib/lt/google/api/auth/cli.rb
lt-google-api-0.2.1 lib/lt/google/api/auth/cli.rb
lt-google-api-0.2.0 lib/lt/google/api/auth/cli.rb
lt-google-api-0.1.1 lib/lt/google/api/auth/cli.rb
lt-google-api-0.1.0 lib/lt/google/api/auth/cli.rb