Repository URL to install this package:
|
Version:
0.4.0 ▾
|
# 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