Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
uoy-faculty-google / lib / faculty / google / auth / service_account.rb
Size: Mime:
# frozen_string_literal: true

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

module Faculty
  module Google
    module Auth
      # Class for handing ServiceAccount logins
      class ServiceAccount
        attr_reader :authorization

        def initialize(creds_file_path: nil, scopes: [])
          # expects GOOGLE_PRIVATE_KEY, GOOGLE_CLIENT_EMAIL and GOOGLE_PROJECT_ID environment variables
          #   if creds_file_path is nil
          @authorization = ::Google::Auth::ServiceAccountCredentials.make_creds(
            json_key_io: creds_file_path.nil? ? nil : File.open(creds_file_path),
            scope: scopes
          )
        end

        def as(email)
          @authorization.sub = email
          self
        end
      end
    end
  end
end