adp-connection 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +202 -0
- data/README.md +56 -0
- data/Rakefile +6 -0
- data/adp-connection.gemspec +39 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/democlient/Gemfile +16 -0
- data/democlient/LICENSE +201 -0
- data/democlient/README.md +2 -0
- data/democlient/Rakefile +9 -0
- data/democlient/adp_connection_ruby.rb +215 -0
- data/democlient/config.ru +24 -0
- data/democlient/config/authorizationcode_config.yml +15 -0
- data/democlient/config/certs/apiclient_iat.key +27 -0
- data/democlient/config/certs/apiclient_iat.pem +45 -0
- data/democlient/config/certs/apiclient_iat.pfx +0 -0
- data/democlient/config/clientcredential_config.yml +11 -0
- data/democlient/public/favicon.ico +0 -0
- data/democlient/public/images/.gitkeep +0 -0
- data/democlient/public/images/ADP_logo_tagline.png +0 -0
- data/democlient/public/images/busy.gif +0 -0
- data/democlient/public/images/hazel_icon.png +0 -0
- data/democlient/public/images/hazel_small.png +0 -0
- data/democlient/public/javascripts/.gitkeep +0 -0
- data/democlient/public/stylesheets/.gitkeep +0 -0
- data/democlient/public/stylesheets/main.css +163 -0
- data/democlient/spec/adp_connection_ruby_spec.rb +14 -0
- data/democlient/spec/spec_helper.rb +23 -0
- data/democlient/views/authorization_code.erb +90 -0
- data/democlient/views/client_credentials.erb +76 -0
- data/democlient/views/layout.erb +40 -0
- data/democlient/views/welcome.erb +34 -0
- data/lib/adp/Product/.gitkeep +0 -0
- data/lib/adp/Product/dto/.gitkeep +0 -0
- data/lib/adp/access_token.rb +44 -0
- data/lib/adp/api_connection.rb +153 -0
- data/lib/adp/api_connection_factory.rb +32 -0
- data/lib/adp/authorization_code_configuration.rb +33 -0
- data/lib/adp/authorization_code_connection.rb +97 -0
- data/lib/adp/client_credential_configuration.rb +18 -0
- data/lib/adp/client_credential_connection.rb +9 -0
- data/lib/adp/connection.rb +16 -0
- data/lib/adp/connection/version.rb +5 -0
- data/lib/adp/connection_configuration.rb +30 -0
- data/lib/adp/connection_exception.rb +12 -0
- metadata +154 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "spec_helper"
|
2
|
+
require_relative "../adp_connection_ruby.rb"
|
3
|
+
|
4
|
+
def app
|
5
|
+
AdpConnectionRuby
|
6
|
+
end
|
7
|
+
|
8
|
+
describe AdpConnectionRuby do
|
9
|
+
it "responds with a welcome message" do
|
10
|
+
get '/'
|
11
|
+
|
12
|
+
last_response.body.must_include 'Welcome to the Sinatra Template!'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
Bundler.setup
|
6
|
+
Bundler.require
|
7
|
+
|
8
|
+
ENV["RACK_ENV"] = "test"
|
9
|
+
|
10
|
+
require 'minitest/pride'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'minitest/spec'
|
13
|
+
require 'rack/test'
|
14
|
+
|
15
|
+
|
16
|
+
require "find"
|
17
|
+
%w{./config/initializers ./lib}.each do |load_path|
|
18
|
+
Find.find(load_path) { |f| require f if f.match(/\.rb$/) }
|
19
|
+
end
|
20
|
+
|
21
|
+
class MiniTest::Spec
|
22
|
+
include Rack::Test::Methods
|
23
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
<div>
|
2
|
+
<p>
|
3
|
+
<strong>Authorization </strong><br/>
|
4
|
+
<a href="/client_credentials" style="width:185px;height:32px;display:inline-block;background-color:#ccc;padding:10px 10px 10px 5px;text-align: center;vertical-align: middle;">Client Credential</a>
|
5
|
+
<span href="authorization_code" style="width:185px;height:32px;display:inline-block;background-color:#ccc;padding:10px 10px 10px 5px;text-align: center;vertical-align: middle;">Authentication Code</span>
|
6
|
+
</p>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="content">
|
10
|
+
<ol>
|
11
|
+
<li><b>1.</b>
|
12
|
+
<% if session["AuthorizationCode"].nil? %>
|
13
|
+
<a href="/authorization_code/login">Login</a>
|
14
|
+
<% else %>
|
15
|
+
<a>Loged in</a>
|
16
|
+
<% end %>
|
17
|
+
<br/>
|
18
|
+
<code>
|
19
|
+
<pre>
|
20
|
+
authorizationcode_config = AuthorizationCodeConfiguration.new(config);
|
21
|
+
connection = ADPApiConnectionFactory::createConnection(authorizationcode_config)
|
22
|
+
authorizationurl = connection.get_authorization_url
|
23
|
+
redirect authorizationurl unless authorizationurl.nil?
|
24
|
+
</pre>
|
25
|
+
</code>
|
26
|
+
</li>
|
27
|
+
<br/>
|
28
|
+
<li><b>2.</b>
|
29
|
+
<% if session["AuthorizationCode"].nil? || session["AuthorizationCode"].connection_configuration.authorizationCode.nil? %>
|
30
|
+
<a>Get Token</a>
|
31
|
+
<% else %>
|
32
|
+
<a href="/authorization_code/get_token">Get Token</a>
|
33
|
+
<% end %>
|
34
|
+
<br/>
|
35
|
+
<code>
|
36
|
+
<pre>
|
37
|
+
#store callback code
|
38
|
+
connection.connection_configuration.authorizationCode = params[:code]
|
39
|
+
#then connect
|
40
|
+
connection.connect()
|
41
|
+
</pre>
|
42
|
+
</code>
|
43
|
+
</li>
|
44
|
+
|
45
|
+
<% if !(session["AuthorizationCode"].nil? || session["AuthorizationCode"].connection_configuration.authorizationCode.nil?) %>
|
46
|
+
|
47
|
+
<li><b>4.</b>
|
48
|
+
<a href="/authorization_code/logout">Logout</a>
|
49
|
+
<code>
|
50
|
+
|
51
|
+
connection.logout()
|
52
|
+
|
53
|
+
</code>
|
54
|
+
</li>
|
55
|
+
<% end %>
|
56
|
+
|
57
|
+
</ol>
|
58
|
+
|
59
|
+
</div>
|
60
|
+
|
61
|
+
<div class="sidebar">
|
62
|
+
<h3>Results...</h3>
|
63
|
+
<ul>
|
64
|
+
<!--
|
65
|
+
<li><b>Ruby:</b> <%= RUBY_VERSION %></li>
|
66
|
+
<li><b>Environment:</b> <%= ENV["RACK_ENV"] %></li>
|
67
|
+
<li><b>Server:</b> <%= @env["SERVER_SOFTWARE"] %></li>
|
68
|
+
<li><b>Port:</b> <%= @env["SERVER_PORT"] %></li>
|
69
|
+
-->
|
70
|
+
<% if session["AuthorizationCode"].nil? %>
|
71
|
+
<li><b>Access token:</b> not logged in</li>
|
72
|
+
<li> </li>
|
73
|
+
<li> </li>
|
74
|
+
<li> </li>
|
75
|
+
<li> </li>
|
76
|
+
<% else %>
|
77
|
+
<li><b>Authorization code:</b> <%= session["AuthorizationCode"].connection_configuration.authorizationCode %> </li>
|
78
|
+
<% unless session["AuthorizationCode"].access_token.nil? %>
|
79
|
+
<li><b>Access token:</b> <%= session["AuthorizationCode"].access_token.token %> </li>
|
80
|
+
<li><b>Token type:</b> <%= session["AuthorizationCode"].access_token.token_type %> </li>
|
81
|
+
<li><b>Expires in:</b> <%= session["AuthorizationCode"].access_token.expires_in %> </li>
|
82
|
+
<li><b>Scope:</b> <%= session["AuthorizationCode"].access_token.scope %> </li>
|
83
|
+
<li><b>Expires on:</b> <%= session["AuthorizationCode"].access_token.expires_on %> </li>
|
84
|
+
<% end %>
|
85
|
+
<% end %>
|
86
|
+
</ul>
|
87
|
+
<div class="results_footer" style="">
|
88
|
+
<a href="https://github.com/adplabs/adp-connection-ruby"><img class="sidebar_logo" src="/images/ADP_logo_tagline.png" alt="Marketplace/Ruby/Library" /></a>
|
89
|
+
</div>
|
90
|
+
</div>
|
@@ -0,0 +1,76 @@
|
|
1
|
+
<div>
|
2
|
+
<p>
|
3
|
+
<strong>Authorization </strong><br/>
|
4
|
+
<span href="client_credentials" style="width:185px;height:32px;display:inline-block;background-color:#ccc;padding:10px 10px 10px 5px;text-align: center;vertical-align: middle;">Client Credential</span>
|
5
|
+
<a href="/authorization_code" style="width:185px;height:32px;display:inline-block;background-color:#ccc;padding:10px 10px 10px 5px;text-align: center;vertical-align: middle;">Authentication Code</a>
|
6
|
+
</p>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="content">
|
10
|
+
<ol>
|
11
|
+
<% if session["ClientCredential"].nil? %>
|
12
|
+
<li><b>1.</b>
|
13
|
+
<a href="/client_credentials/login">Login</a>
|
14
|
+
<code>
|
15
|
+
<pre>
|
16
|
+
clientcredential_config = ClientCredentialConfiguration.new(config);
|
17
|
+
connection = ADPApiConnectionFactory::createConnection(clientcredential_config)
|
18
|
+
connection.connect();
|
19
|
+
</pre>
|
20
|
+
</code>
|
21
|
+
</li>
|
22
|
+
<% end %>
|
23
|
+
<% if !session["ClientCredential"].nil? %>
|
24
|
+
<li><b>1.</b>
|
25
|
+
<a>Logged in</a>
|
26
|
+
<code>
|
27
|
+
<pre>
|
28
|
+
clientcredential_config = ClientCredentialConfiguration.new(config);
|
29
|
+
connection = ADPApiConnectionFactory::createConnection(clientcredential_config)
|
30
|
+
connection.connect();
|
31
|
+
</pre>
|
32
|
+
</code>
|
33
|
+
</li>
|
34
|
+
<br/>
|
35
|
+
<li><b>2.</b>
|
36
|
+
<a href="/client_credentials/logout">Logout</a>
|
37
|
+
<br/>
|
38
|
+
<code>
|
39
|
+
|
40
|
+
connection.logout()
|
41
|
+
|
42
|
+
</code>
|
43
|
+
</li>
|
44
|
+
<% end %>
|
45
|
+
<br/>
|
46
|
+
<!-- <li><b>2.</b> <a>Get Data</a></li> -->
|
47
|
+
<br/>
|
48
|
+
</ol>
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div class="sidebar">
|
52
|
+
<h3>Results...</h3>
|
53
|
+
<ul>
|
54
|
+
<!--
|
55
|
+
<li><b>Ruby:</b> <%= RUBY_VERSION %></li>
|
56
|
+
<li><b>Environment:</b> <%= ENV["RACK_ENV"] %></li>
|
57
|
+
<li><b>Server:</b> <%= @env["SERVER_SOFTWARE"] %></li>
|
58
|
+
<li><b>Port:</b> <%= @env["SERVER_PORT"] %></li>
|
59
|
+
-->
|
60
|
+
|
61
|
+
<% if session["ClientCredential"].nil? || session["ClientCredential"].access_token.nil? %>
|
62
|
+
<li><b>Access token:</b> not logged in</li>
|
63
|
+
<% else %>
|
64
|
+
<li><b>Access token:</b> <%= session["ClientCredential"].access_token.token %> </li>
|
65
|
+
<li><b>Token type:</b> <%= session["ClientCredential"].access_token.token_type %> </li>
|
66
|
+
<li><b>Expires in:</b> <%= session["ClientCredential"].access_token.expires_in %> </li>
|
67
|
+
<li><b>Scope:</b> <%= session["ClientCredential"].access_token.scope %> </li>
|
68
|
+
<li><b>Expires on:</b> <%= session["ClientCredential"].access_token.expires_on %> </li>
|
69
|
+
<% end %>
|
70
|
+
<li> </li>
|
71
|
+
</ul>
|
72
|
+
|
73
|
+
<div class="results_footer">
|
74
|
+
<a href="https://github.com/adplabs/adp-connection-ruby"><img class="sidebar_logo" src="/images/ADP_logo_tagline.png" alt="Marketplace/Ruby/Library" /></a>
|
75
|
+
</div>
|
76
|
+
</div>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
|
3
|
+
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
|
4
|
+
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
|
5
|
+
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
|
6
|
+
<head>
|
7
|
+
<meta charset="utf-8" />
|
8
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
|
9
|
+
|
10
|
+
<title>Adp Connection API Library (Ruby)</title>
|
11
|
+
|
12
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
13
|
+
|
14
|
+
<link rel="stylesheet" href="/stylesheets/main.css" />
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<div class="wrapper">
|
18
|
+
<header class="branding">
|
19
|
+
<h1>Adp Connection API Library (Ruby)</h1>
|
20
|
+
</header>
|
21
|
+
|
22
|
+
<div class="main">
|
23
|
+
<%= yield %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<footer class="branding error">
|
27
|
+
<%= view_bag[:message] %>
|
28
|
+
<hr/>
|
29
|
+
<small>© <%= Time.now.year %></small>
|
30
|
+
<hr/>
|
31
|
+
</footer>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
|
35
|
+
<!--[if lt IE 7]>
|
36
|
+
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.min.js"></script>
|
37
|
+
<script>window.attachEvent("onload",function(){CFInstall.check({mode:"overlay"})})</script>
|
38
|
+
<![endif]-->
|
39
|
+
</body>
|
40
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
<div>
|
2
|
+
<p>
|
3
|
+
<strong>Authorization </strong><br/>
|
4
|
+
<a href="/client_credentials" style="width:185px;height:32px;display:inline-block;background-color:#ccc;padding:10px 10px 10px 5px;text-align: center;vertical-align: middle;">Client Credential</a>
|
5
|
+
<a href="/authorization_code" style="width:185px;height:32px;display:inline-block;background-color:#ccc;padding:10px 10px 10px 5px;text-align: center;vertical-align: middle;">Authentication Code</a>
|
6
|
+
</p>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="content">
|
10
|
+
<ol>
|
11
|
+
</ol>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="sidebar">
|
15
|
+
<h3>Results...</h3>
|
16
|
+
<ul>
|
17
|
+
<!--
|
18
|
+
<li><b>Ruby:</b> <%= RUBY_VERSION %></li>
|
19
|
+
<li><b>Environment:</b> <%= ENV["RACK_ENV"] %></li>
|
20
|
+
<li><b>Server:</b> <%= @env["SERVER_SOFTWARE"] %></li>
|
21
|
+
<li><b>Port:</b> <%= @env["SERVER_PORT"] %></li>
|
22
|
+
-->
|
23
|
+
|
24
|
+
<li></li>
|
25
|
+
<li></li>
|
26
|
+
<li></li>
|
27
|
+
<li></li>
|
28
|
+
<li></li>
|
29
|
+
<li></li>
|
30
|
+
</ul>
|
31
|
+
<div class="results_footer">
|
32
|
+
<a href="https://github.com/adplabs/adp-connection-ruby"><img class="sidebar_logo" src="/images/ADP_logo_tagline.png" alt="Marketplace/Ruby/Library" /></a>
|
33
|
+
</div>
|
34
|
+
</div>
|
File without changes
|
File without changes
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Adp
|
2
|
+
module Connection
|
3
|
+
|
4
|
+
class AccessToken
|
5
|
+
attr_accessor :token
|
6
|
+
attr_accessor :token_type
|
7
|
+
attr_accessor :scope
|
8
|
+
attr_accessor :expires_on
|
9
|
+
attr_accessor :token
|
10
|
+
attr_accessor :_expires_in
|
11
|
+
|
12
|
+
# @return [Object]
|
13
|
+
def initialize(config = nil)
|
14
|
+
|
15
|
+
unless config.nil?
|
16
|
+
self.token = config["access_token"]
|
17
|
+
self.token_type = config["token_type"]
|
18
|
+
self.scope = config["scope"]
|
19
|
+
self.expires_in = config["expires_in"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Object]
|
24
|
+
def expires_in=(value)
|
25
|
+
unless value.nil?
|
26
|
+
self._expires_in = value
|
27
|
+
self.expires_on = Time.new() + self._expires_in
|
28
|
+
end
|
29
|
+
self.expires_on
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Object]
|
33
|
+
def expires_in
|
34
|
+
return self._expires_in
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_valid?
|
38
|
+
return true;
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/https'
|
3
|
+
require 'base64'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require_relative "connection_configuration"
|
7
|
+
require_relative 'access_token'
|
8
|
+
require_relative "connection_exception"
|
9
|
+
require_relative "api_connection"
|
10
|
+
require_relative "client_credential_configuration"
|
11
|
+
require_relative "authorization_code_configuration"
|
12
|
+
|
13
|
+
module Adp
|
14
|
+
module Connection
|
15
|
+
|
16
|
+
class ApiConnection
|
17
|
+
attr_accessor :connection_configuration
|
18
|
+
attr_accessor :token_expiration
|
19
|
+
attr_accessor :state
|
20
|
+
attr_accessor :access_token
|
21
|
+
|
22
|
+
# @param [Object] config
|
23
|
+
def initialize( config = nil )
|
24
|
+
self.connection_configuration = config;
|
25
|
+
end
|
26
|
+
|
27
|
+
def connect
|
28
|
+
|
29
|
+
if self.connection_configuration.nil?
|
30
|
+
raise ADPConnectionException, "Configuration is empty or not found"
|
31
|
+
end
|
32
|
+
|
33
|
+
self.access_token = get_access_token()
|
34
|
+
end
|
35
|
+
|
36
|
+
def disconnect
|
37
|
+
self.access_token = null;
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [Boolean]
|
41
|
+
def is_connected_indicator?
|
42
|
+
|
43
|
+
is_connected = false;
|
44
|
+
|
45
|
+
if (!self.access_token.nil?)
|
46
|
+
# valid token to check if expired
|
47
|
+
is_connected = true if Time.new() < self.access_token.expires_on
|
48
|
+
end
|
49
|
+
|
50
|
+
return is_connected
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_access_token
|
54
|
+
token = self.access_token;
|
55
|
+
result = nil;
|
56
|
+
|
57
|
+
if is_connected_indicator?
|
58
|
+
|
59
|
+
if self.connection_configuration.nil?
|
60
|
+
raise ADPConnectionException, "Config error: Configuration is empty or not found"
|
61
|
+
end
|
62
|
+
if (self.connection_configuration.grantType.nil?)
|
63
|
+
raise ADPConnectionException, "Config error: Grant Type is empty or not known"
|
64
|
+
end
|
65
|
+
if (self.connection_configuration.tokenServerURL.nil?)
|
66
|
+
raise ADPConnectionException, "Config error: tokenServerURL is empty or not known"
|
67
|
+
end
|
68
|
+
if (self.connection_configuration.clientID.nil?)
|
69
|
+
raise ADPConnectionException, "Config error: clientID is empty or not known"
|
70
|
+
end
|
71
|
+
if (self.connection_configuration.clientSecret.nil?)
|
72
|
+
raise ADPConnectionException, "Config error: clientSecret is empty or not known"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
data = {
|
77
|
+
"client_id" => self.connection_configuration.clientID,
|
78
|
+
"client_secret" => self.connection_configuration.clientSecret,
|
79
|
+
"grant_type" => self.connection_configuration.grantType
|
80
|
+
};
|
81
|
+
|
82
|
+
result = send_web_request(self.connection_configuration.tokenServerURL, data );
|
83
|
+
|
84
|
+
if result["error"].nil? then
|
85
|
+
token = AccessToken.new(result)
|
86
|
+
else
|
87
|
+
raise ADPConnectionException, "Connection error: #{result['error_description']}"
|
88
|
+
end
|
89
|
+
|
90
|
+
token
|
91
|
+
end
|
92
|
+
|
93
|
+
# @return [Object]
|
94
|
+
def get_adp_data(product_url)
|
95
|
+
|
96
|
+
raise ADPConnectionException, "Connection error: can't get data, not connected" if (self.access_token.nil? || !is_connected_indicator?)
|
97
|
+
|
98
|
+
authorization = "#{self.access_token.token_type} #{self.access_token.token}"
|
99
|
+
|
100
|
+
data = {
|
101
|
+
"client_id" => self.connection_configuration.clientID,
|
102
|
+
"client_secret" => self.connection_configuration.clientSecret,
|
103
|
+
"grant_type" => self.connection_configuration.grantType,
|
104
|
+
"code" => self.connection_configuration.authorizationCode,
|
105
|
+
"redirect_uri" => self.connection_configuration.redirectURL
|
106
|
+
};
|
107
|
+
|
108
|
+
data = send_web_request(product_url, data, authorization, 'application/json', 'GET')
|
109
|
+
|
110
|
+
raise ADPConnectionException, "Connection error: #{data['error']}, #{data['error_description']}" unless data["error"].nil?
|
111
|
+
|
112
|
+
return data
|
113
|
+
end
|
114
|
+
|
115
|
+
def send_web_request(url, data={}, authorization=nil, content_type=nil, method=nil)
|
116
|
+
|
117
|
+
data ||= {}
|
118
|
+
content_type ||= "application/x-www-form-urlencoded"
|
119
|
+
method ||= 'POST'
|
120
|
+
|
121
|
+
Log.debug("URL: #{url}")
|
122
|
+
Log.debug("Client ID: #{data["client_id"]}")
|
123
|
+
Log.debug("Client Secret: #{data["client_secret"]}")
|
124
|
+
Log.debug("Grant Type: #{data["grant_type"]}")
|
125
|
+
|
126
|
+
uri = URI.parse( url );
|
127
|
+
pem = File.read("#{self.connection_configuration.sslCertPath}");
|
128
|
+
key = File.read(self.connection_configuration.sslKeyPath);
|
129
|
+
http = Net::HTTP.new(uri.host, uri.port);
|
130
|
+
if (!self.connection_configuration.sslCertPath.nil?)
|
131
|
+
http.use_ssl = true
|
132
|
+
http.cert = OpenSSL::X509::Certificate.new( pem );
|
133
|
+
http.key = OpenSSL::PKey::RSA.new(key, self.connection_configuration.sslKeyPass);
|
134
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
135
|
+
end
|
136
|
+
|
137
|
+
if method.eql?('POST')
|
138
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
139
|
+
request.set_form_data( data );
|
140
|
+
else
|
141
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
142
|
+
end
|
143
|
+
|
144
|
+
request["Content-Type"] = content_type
|
145
|
+
|
146
|
+
# add credentials if available
|
147
|
+
request["Authorization"] = authorization unless authorization.nil?
|
148
|
+
|
149
|
+
response = JSON.parse(http.request(request).body)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|