Class: GoogleWallet::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/google_wallet/authentication.rb

Constant Summary collapse

SCOPE =
'https://www.googleapis.com/auth/wallet_object.issuer'

Instance Method Summary collapse

Constructor Details

#initializeAuthentication

Returns a new instance of Authentication.



9
10
11
# File 'lib/google_wallet/authentication.rb', line 9

def initialize
  @credentials = GoogleWallet.configuration.json_credentials
end

Instance Method Details

#access_tokenObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/google_wallet/authentication.rb', line 13

def access_token
  if @credentials
    begin
      credentials = Google::Auth::ServiceAccountCredentials.make_creds(
        json_key_io: StringIO.new(@credentials.to_json),
        scope: SCOPE
      )

      credentials.fetch_access_token!
      credentials.access_token
    rescue StandardError => e
      puts "Error while fetching access token: #{e.message}"
      nil
    end
  else
    puts "No credentials provided."
    nil
  end
end