Sha256: 81f9e01fd3040eb4729a67b1133e7768169f19694120f98ee3f0bcedaaf2da33

Contents?: true

Size: 1.42 KB

Versions: 23

Compression:

Stored size: 1.42 KB

Contents

require File.dirname(__FILE__) + "/../cli/setup"


SparkApi.configure do |config|
  oauth = {
    :authorization_uri=> ENV.fetch("AUTH_URI", SparkApi::Configuration::DEFAULT_AUTHORIZATION_URI),
    :access_uri  => ENV.fetch("ACCESS_URI", SparkApi::Configuration::DEFAULT_ACCESS_URI),
    :redirect_uri  => ENV.fetch("REDIRECT_URI", SparkApi::Configuration::DEFAULT_REDIRECT_URI),
    :client_id=> ENV["CLIENT_ID"],
    :client_secret=> ENV["CLIENT_SECRET"]
  }
  oauth[:username] = ENV["USERNAME"] if ENV.include?("USERNAME")
  oauth[:password] = ENV["PASSWORD"] if ENV.include?("PASSWORD")
  config.oauth2_provider = SparkApi::Authentication::OAuth2Impl::CLIProvider.new(oauth)
  unless (oauth.include?(:username) && oauth.include?(:password))
    config.oauth2_provider.grant_type = :authorization_code 
    config.oauth2_provider.code = ENV["CODE"] if ENV.include?("CODE")
  end
  config.authentication_mode = SparkApi::Authentication::OAuth2
  config.endpoint = ENV["API_ENDPOINT"] if ENV["API_ENDPOINT"]
  config.ssl_verify = ENV["SSL_VERIFY"].downcase != 'false' if ENV["SSL_VERIFY"]
end

# Enables saving and loading serialized oauth2 sessions for the system user. 
def persist_sessions! my_alias = nil
  warn "Warning: persistent session mode saves access tokens in clear text on the filesystem."
  SparkApi.client.oauth2_provider.session_alias = my_alias unless my_alias.nil?
  SparkApi.client.oauth2_provider.persistent_sessions = true
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
spark_api-1.4.14 lib/spark_api/cli/oauth2.rb
spark_api-1.4.13 lib/spark_api/cli/oauth2.rb
spark_api-1.4.12 lib/spark_api/cli/oauth2.rb
spark_api-1.4.11 lib/spark_api/cli/oauth2.rb
spark_api-1.4.10 lib/spark_api/cli/oauth2.rb
spark_api-1.4.9 lib/spark_api/cli/oauth2.rb
spark_api-1.4.8 lib/spark_api/cli/oauth2.rb
spark_api-1.4.6 lib/spark_api/cli/oauth2.rb
spark_api-1.4.5 lib/spark_api/cli/oauth2.rb
spark_api-1.4.4 lib/spark_api/cli/oauth2.rb
spark_api-1.4.2 lib/spark_api/cli/oauth2.rb
spark_api-1.4.1 lib/spark_api/cli/oauth2.rb
spark_api-1.4.0 lib/spark_api/cli/oauth2.rb
spark_api-1.3.28 lib/spark_api/cli/oauth2.rb
spark_api-1.3.27 lib/spark_api/cli/oauth2.rb
spark_api-1.3.26 lib/spark_api/cli/oauth2.rb
spark_api-1.3.25 lib/spark_api/cli/oauth2.rb
spark_api-1.3.24 lib/spark_api/cli/oauth2.rb
spark_api-1.3.23 lib/spark_api/cli/oauth2.rb
spark_api-1.3.21 lib/spark_api/cli/oauth2.rb