Skip to content

Access Token Authentication

dgmyrek edited this page Feb 13, 2018 · 1 revision

If you've been provided with a permanent (non-expiring) access token this authentication method allows you to skip all tasks that require user authorization handling and begin retrieving data from the API immediately.

Example

require 'spark_api'

# Initial setup consists of requiring the gem and setting the appropriate authentication mode
# One option is required:
#  - authentication_mode: SparkApi::Authentication::OAuth2
# other applicable options and their defaults:
#  - endpoint:   'https://api.sparkapi.com'
#  - version:    'v1'
#  - ssl:        true
#  - user_agent: 'Spark API Ruby Gem'

SparkApi.configure do |config|
    config.authentication_mode = SparkApi::Authentication::OAuth2
end

# To initialize the session pass in your access token
SparkApi.client.session = SparkApi::Authentication::OAuthSession.new({ :access_token => "YOUR_ACCESS_TOKEN_HERE" })

# Start retrieving data
SparkApi.client.get "/system"

Spark Platform Documentation

Access Token Authentication