Skip to content

Instantly share code, notes, and snippets.

@ffaerber
Last active February 5, 2016 17:39
Show Gist options
  • Save ffaerber/cec380fbdc65454f4705 to your computer and use it in GitHub Desktop.
Save ffaerber/cec380fbdc65454f4705 to your computer and use it in GitHub Desktop.
require 'omniauth-oauth2'
module OmniAuth
module Strategies
class Figo < OmniAuth::Strategies::OAuth2
# Give your strategy a name.
option :name, "figo"
# This is where you pass the options you would pass when
# initializing your consumer from the OAuth gem.
option :client_options, {
site: 'https://api.figo.me',
authorize_url: '/auth/code',
token_url: '/auth/token'
}
def build_access_token
options.token_params.merge!(:headers => {'Authorization' => basic_auth_header })
super
end
def basic_auth_header
"Basic " + Base64.strict_encode64("#{options[:client_id]}:#{options[:client_secret]}")
end
def query_string
''
end
# These are called after authentication has succeeded. If
# possible, you should try to set the UID without making
# additional calls (if the user id is returned with the token
# or as a URI parameter). This may not be possible with all
# providers.
uid{
user['user_id']
}
def user
MultiJson.load(access_token.get('https://api.figo.me/rest/user').body)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment