-
Notifications
You must be signed in to change notification settings - Fork 34
Hybrid Authentication
wlmcewen edited this page Nov 7, 2012
·
3 revisions
With the newest release of the API, you can now authenticate using 'OpenId' and 'OAuth2' method (opposed to just the 'OAuth2' alone method). This page goes over the new Hybrid Authentication:
# initialize the gem with your key/secret.
# See also: script/combined_flow_example.rb
# api_key, api_secret, and callback are all required.
# The following options are required:
# - api_key: Your client key
# - api_secret: Your client secret
# - callback: Your redirect_uri, which the end user will be redirected
# to after authorizing your application to access their data.
# - auth_endpoint: The URI to redirect the user's web browser to, in order for them to
# authorize your application to access their data.
# other 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::OpenIdOAuth2Hybrid
config.api_key = "YOUR_CLIENT_ID"
config.api_secret = "YOUR_CLIENT_SECRET"
config.callback = "YOUR_REDIRECT_URI"
config.auth_endpoint = "https://sparkplatform.com/openid"
config.endpoint = 'https://sparkapi.com'
end
# Code is retrieved from the method: SparkApi.client.authenticator.authorization_url
# See script/combined_flow_example.rb for more details.
SparkApi.client.oauth2_provider.code = "CODE_FROM_ABOVE_URI"
SparkApi.client.authenticate
# Alternatively, if you've already received an access token, you may
# do the following instead of the above two lines:
# SparkApi.client.session = SparkApi::Authentication::OAuthSession.new "access_token"=> "ACCESS_TOKEN",
# "refresh_token" => "REFRESH_TOKEN", "expires_in" => 86400
SparkApi.client.get "/system"
Also checkout the example script at "script/combined_flow_example.rb".