Module: Lexdrill::ServiceAccountAuth

Defined in:
lib/lexdrill/service_account_auth.rb

Overview

Authenticates to the Sheets API as a Google service account, using the JWT Bearer Token flow (RFC 7523) — no interactive consent, no refresh token to cache: a fresh short-lived JWT is signed and exchanged for an access token on every call. The service account's private key lives in a JSON file the user downloads themselves from Google Cloud Console and saves locally at PATH below — it is never embedded in gem source, never published, and lexdrill never writes or transmits it anywhere except in the signed JWT sent directly to Google's own token endpoint.

Defined Under Namespace

Classes: AuthError

Constant Summary collapse

PATH =
File.join(Dir.home, ".drill.gcp-service-account.json")
TOKEN_URL =
"https://oauth2.googleapis.com/token"
SCOPE =
"https://www.googleapis.com/auth/spreadsheets"
GRANT_TYPE =
"urn:ietf:params:oauth:grant-type:jwt-bearer"
TOKEN_LIFETIME =
3600

Class Method Summary collapse

Class Method Details

.configured?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/lexdrill/service_account_auth.rb', line 24

def self.configured?
  File.exist?(PATH)
end

.fetch_token!Object



28
29
30
31
32
# File 'lib/lexdrill/service_account_auth.rb', line 28

def self.fetch_token!
  key = load_key
  jwt = build_jwt(key)
  exchange_jwt(jwt)
end