Module: Fastlane::Auth::FirebaseAppDistributionAuthClient

Constant Summary collapse

TOKEN_CREDENTIAL_URI =
"https://oauth2.googleapis.com/token"
REDACTION_EXPOSED_LENGTH =
5
REDACTION_CHARACTER =
"X"

Instance Method Summary collapse

Instance Method Details

#fetch_auth_token(google_service_path, firebase_cli_token, debug = false) ⇒ Object

Returns the auth token for any of the auth methods (Firebase CLI token, Google service account, firebase-tools). To ensure that a specific auth method is used, unset all other auth variables/parameters to nil/empty

args

google_service_path - Absolute path to the Google service account file
firebase_cli_token - Firebase CLI refresh token from login action or
                     CI environment
debug - Whether to enable debug-level logging

env variables

GOOGLE_APPLICATION_CREDENTIALS - see google_service_path
FIREBASE_TOKEN - see firebase_cli_token

Crashes if given invalid or missing credentials



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fastlane/plugin/firebase_app_distribution/helper/firebase_app_distribution_auth_client.rb', line 25

def fetch_auth_token(google_service_path, firebase_cli_token, debug = false)
  if !google_service_path.nil? && !google_service_path.empty?
    UI.message("🔐 Authenticating with --service_credentials_file path parameter: #{google_service_path}")
    token = (google_service_path, debug)
  elsif !firebase_cli_token.nil? && !firebase_cli_token.empty?
    UI.message("🔐 Authenticating with --firebase_cli_token parameter")
    token = firebase_token(firebase_cli_token, debug)
  elsif !ENV["FIREBASE_TOKEN"].nil? && !ENV["FIREBASE_TOKEN"].empty?
    UI.message("🔐 Authenticating with FIREBASE_TOKEN environment variable")
    token = firebase_token(ENV["FIREBASE_TOKEN"], debug)
  elsif !ENV["GOOGLE_APPLICATION_CREDENTIALS"].nil? && !ENV["GOOGLE_APPLICATION_CREDENTIALS"].empty?
    UI.message("🔐 Authenticating with GOOGLE_APPLICATION_CREDENTIALS environment variable: #{ENV['GOOGLE_APPLICATION_CREDENTIALS']}")
    token = (ENV["GOOGLE_APPLICATION_CREDENTIALS"], debug)
  elsif (refresh_token = refresh_token_from_firebase_tools)
    UI.message("🔐 No authentication method specified. Using cached Firebase CLI credentials.")
    token = firebase_token(refresh_token, debug)
  else
    UI.user_error!(ErrorMessage::MISSING_CREDENTIALS)
  end
  token
end