All Files
(64.52%
covered at
0.77
hits/line)
4 files in total.
31 relevant lines.
20 lines covered and
11 lines missed
-
# Monkeypatching to work with how Active Passport names the access token on a successful response
-
-
1
module OAuth2
-
# The OAuth2::Client class
-
1
class Client
-
# Initializes an AccessToken by making a request to the token endpoint
-
1
def get_token(params, access_token_opts={})
-
opts = {:raise_errors => true, :parse => params.delete(:parse)}
-
if options[:token_method] == :post
-
opts[:body] = params
-
opts[:headers] = {'Content-Type' => 'application/x-www-form-urlencoded'}
-
else
-
opts[:params] = params
-
end
-
response = request(options[:token_method], token_url, opts)
-
raise Error.new(response) unless response.parsed.is_a?(Hash) && (response.parsed['access_token'] || response.parsed['accessToken'])
-
AccessToken.from_hash(self, response.parsed.merge(access_token_opts))
-
end
-
end
-
end
-
1
require "omniauth-active_passport/version"
-
1
require 'omniauth/strategies/active_passport'
-
1
module Omniauth
-
1
module ActivePassport
-
1
VERSION = "0.0.1"
-
end
-
end
-
1
require 'omniauth-oauth2'
-
1
require 'oauth2_patch/client'
-
-
1
module OmniAuth
-
1
module Strategies
-
1
class ActivePassport < OmniAuth::Strategies::OAuth2
-
# Give your strategy a name.
-
1
option :name, "active_passport"
-
-
# This is where you pass the options you would pass when
-
# initializing your consumer from the OAuth gem.
-
1
option :client_options, {
-
:site => 'https://passport.active.com',
-
:authorize_url => '/oauth2/authorize',
-
:token_url => '/oauth2/token'
-
}
-
-
1
option :token_params, { :parse => :json }
-
-
1
uid { access_token.params['activeEnterprisePersonId'] }
-
-
1
info do
-
{
-
:email => access_token.params['userName'],
-
:expires_at => access_token.params['expireDateTime']
-
}
-
end
-
-
1
credentials do
-
{
-
:token => access_token.params['accessToken']
-
}
-
end
-
-
1
extra do
-
{
-
:access_token => access_token
-
}
-
end
-
end
-
end
-
end