Sha256: 8e6830d0b69d30accbfb7bc46dc0a91dfbcfaf1cf6fd8436a10d601b3a0b3fa0

Contents?: true

Size: 908 Bytes

Versions: 7

Compression:

Stored size: 908 Bytes

Contents

require "securerandom"

module TokenHelpers
  # Creates a cached access token for the config directly to disk
  def cache_access_token(config, token)
    File.open(config.access_token_filename, "w") { |f| f.write token }
  end

  # Creates a cached refresh token for the config directly to disk
  def cache_refresh_token(config, token)
    File.open(config.refresh_token_filename, "w") {|f| f.write token }
  end

  # Returns the cached access token for the config directly from disk
  def cached_access_token(config)
    File.read(config.access_token_filename).chomp
  end

  # Returns the cached refresh token for the config directly from disk
  def cached_refresh_token(config)
    File.read(config.refresh_token_filename).chomp
  end

  # This returns a token like string with no meaning but should always be
  # different so never clashes in tests.
  def random_token
    SecureRandom.hex(20)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
brightbox-cli-1.2.2 spec/support/token_helpers.rb
brightbox-cli-1.2.1 spec/support/token_helpers.rb
brightbox-cli-1.2.0 spec/support/token_helpers.rb
brightbox-cli-1.1.0 spec/support/token_helpers.rb
brightbox-cli-1.0.0 spec/support/token_helpers.rb
brightbox-cli-1.0.0.rc2 spec/support/token_helpers.rb
brightbox-cli-1.0.0.rc1 spec/support/token_helpers.rb