Sha256: a8707a7457022c3a02b86142fb36bd8c24e5d73118b1b91a0e046d2fe5dd343b

Contents?: true

Size: 909 Bytes

Versions: 40

Compression:

Stored size: 909 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

40 entries across 40 versions & 1 rubygems

Version Path
brightbox-cli-3.3.0 spec/support/token_helpers.rb
brightbox-cli-3.2.0 spec/support/token_helpers.rb
brightbox-cli-3.1.0 spec/support/token_helpers.rb
brightbox-cli-3.0.1 spec/support/token_helpers.rb
brightbox-cli-3.0.0 spec/support/token_helpers.rb
brightbox-cli-2.12.0 spec/support/token_helpers.rb
brightbox-cli-2.11.2 spec/support/token_helpers.rb
brightbox-cli-2.11.1 spec/support/token_helpers.rb
brightbox-cli-2.11.0 spec/support/token_helpers.rb
brightbox-cli-2.10.0 spec/support/token_helpers.rb
brightbox-cli-2.9.3 spec/support/token_helpers.rb
brightbox-cli-2.9.2 spec/support/token_helpers.rb
brightbox-cli-2.9.1 spec/support/token_helpers.rb
brightbox-cli-2.9.0 spec/support/token_helpers.rb
brightbox-cli-2.8.2 spec/support/token_helpers.rb
brightbox-cli-2.8.1 spec/support/token_helpers.rb
brightbox-cli-2.8.0 spec/support/token_helpers.rb
brightbox-cli-2.7.1 spec/support/token_helpers.rb
brightbox-cli-2.7.0 spec/support/token_helpers.rb
brightbox-cli-2.6.0 spec/support/token_helpers.rb