adp-product-userinfo 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +42 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +201 -0
  8. data/README.md +253 -0
  9. data/Rakefile +6 -0
  10. data/adp-product-userinfo.gemspec +41 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/democlient/Gemfile +16 -0
  14. data/democlient/Gemfile.lock +47 -0
  15. data/democlient/LICENSE +201 -0
  16. data/democlient/README.md +2 -0
  17. data/democlient/Rakefile +9 -0
  18. data/democlient/adp_userinfo_ruby.rb +216 -0
  19. data/democlient/config.ru +24 -0
  20. data/democlient/config/authorizationcode_config.yml +15 -0
  21. data/democlient/config/certs/apiclient_iat.key +27 -0
  22. data/democlient/config/certs/apiclient_iat.pem +45 -0
  23. data/democlient/config/certs/apiclient_iat.pfx +0 -0
  24. data/democlient/config/clientcredential_config.yml +11 -0
  25. data/democlient/public/favicon.ico +0 -0
  26. data/democlient/public/images/.gitkeep +0 -0
  27. data/democlient/public/images/ADP_logo_tagline.png +0 -0
  28. data/democlient/public/images/busy.gif +0 -0
  29. data/democlient/public/images/hazel_icon.png +0 -0
  30. data/democlient/public/images/hazel_small.png +0 -0
  31. data/democlient/public/javascripts/.gitkeep +0 -0
  32. data/democlient/public/stylesheets/.gitkeep +0 -0
  33. data/democlient/public/stylesheets/main.css +225 -0
  34. data/democlient/spec/adp_connection_ruby_spec.rb +14 -0
  35. data/democlient/spec/spec_helper.rb +23 -0
  36. data/democlient/views/authorization_code.erb +128 -0
  37. data/democlient/views/client_credentials.erb +76 -0
  38. data/democlient/views/layout.erb +52 -0
  39. data/democlient/views/welcome.erb +33 -0
  40. data/lib/adp/product/dto/user_info.rb +30 -0
  41. data/lib/adp/product/userinfo.rb +11 -0
  42. data/lib/adp/product/userinfo/helper.rb +40 -0
  43. data/lib/adp/product/userinfo/version.rb +7 -0
  44. metadata +162 -0
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'adp/product/userinfo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "adp-product-userinfo"
8
+ spec.version = Adp::Product::Userinfo::VERSION
9
+ spec.authors = ["Napier, Junior (CORP)"]
10
+ spec.email = ["Junior.Napier@gmail.com"]
11
+ # spec.owners = ["ADP Marketplace, ADP Inc."]
12
+
13
+ spec.summary = %q{ADP Ruby UserInfo product client library to get the logged-in user's info.}
14
+ spec.description = %q{The ADP UserInfo Product Library can be used to obtain basic information about the user that is logged-in to the ADP application. The Library includes a sample application that can be run out-of-the-box to connect to the ADP Marketplace API test gateway. This library has a dependancy on the adp-connection library. Installing this library also installs the latest version of the adp-connection library, if not previously installed.}
15
+ spec.homepage = "https://github.com/adplabs/adp-userinfo-ruby"
16
+ spec.license = "Apache-2.0"
17
+
18
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
+ # delete this section to allow pushing this gem to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # spec.add_dependency "uri"
32
+ # spec.add_dependency "net/https"
33
+ # spec.add_dependency "base64"
34
+ spec.add_dependency "json", '~> 1.8'
35
+ # spec.add_dependency 'securerandom'
36
+ spec.add_dependency 'adp-connection'
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.11"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "adp/product/userinfo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ source "https://rubygems.org/"
2
+
3
+ # adp library
4
+ gem "adp-connection"
5
+ gem "adp-product-userinfo"
6
+
7
+ # App Stack
8
+ gem "sinatra", "~> 1.4"
9
+ gem "sinatra-config-file"
10
+
11
+
12
+ group :development do
13
+ gem "rake", "~> 10.0"
14
+ gem "minitest", "~> 5.2"
15
+ gem "rack-test", "~> 0.6"
16
+ end
@@ -0,0 +1,47 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ adp-connection (0.1.1)
5
+ json (~> 1.8)
6
+ adp-product-userinfo (0.1.0)
7
+ adp-connection
8
+ json (~> 1.8)
9
+ backports (3.6.8)
10
+ json (1.8.3)
11
+ minitest (5.8.4)
12
+ multi_json (1.11.2)
13
+ rack (1.6.4)
14
+ rack-protection (1.5.3)
15
+ rack
16
+ rack-test (0.6.3)
17
+ rack (>= 1.0)
18
+ rake (10.5.0)
19
+ sinatra (1.4.7)
20
+ rack (~> 1.5)
21
+ rack-protection (~> 1.4)
22
+ tilt (>= 1.3, < 3)
23
+ sinatra-config-file (1.0)
24
+ sinatra-contrib
25
+ sinatra-contrib (1.4.6)
26
+ backports (>= 2.0)
27
+ multi_json
28
+ rack-protection
29
+ rack-test
30
+ sinatra (~> 1.4.0)
31
+ tilt (>= 1.3, < 3)
32
+ tilt (2.0.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ adp-connection
39
+ adp-product-userinfo
40
+ minitest (~> 5.2)
41
+ rack-test (~> 0.6)
42
+ rake (~> 10.0)
43
+ sinatra (~> 1.4)
44
+ sinatra-config-file
45
+
46
+ BUNDLED WITH
47
+ 1.11.2
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ # adp-userinfo-ruby
2
+ ADP Ruby UserInfo product client library to get the logged-in user's info
@@ -0,0 +1,9 @@
1
+ %w{ bundler find rake/testtask}.each { |lib| require lib }
2
+
3
+ task :default => :spec
4
+
5
+ Rake::TestTask.new(:spec) do |t|
6
+ t.test_files = FileList['spec/*_spec.rb']
7
+ end
8
+
9
+
@@ -0,0 +1,216 @@
1
+ require 'yaml'
2
+ require 'tilt/erb'
3
+ require 'logger'
4
+ require 'adp/connection'
5
+ require 'adp/product/userinfo'
6
+
7
+ clientcredential_config = YAML.load(ERB.new(File.read('config/clientcredential_config.yml')).result)
8
+ authorizationcode_config = YAML.load(ERB.new(File.read('config/authorizationcode_config.yml')).result)
9
+
10
+ configure do
11
+ Log = Logger.new(STDOUT);
12
+ #Logger.new("sinatra.log")
13
+ Log.level = Logger::DEBUG
14
+ end
15
+
16
+ class AdpConnectionRuby < Sinatra::Base
17
+
18
+ enable :sessions
19
+ set :public_folder => "public", :static => true
20
+
21
+ #set :protection, :session => true
22
+ set :port, 8889
23
+
24
+ results = {
25
+ :message => "Welcome",
26
+ :auth_type => nil
27
+ }
28
+
29
+
30
+ before do
31
+
32
+ # request.path_info = '/foo/bar/baz'
33
+ end
34
+
35
+ after do
36
+ # erb :welcome, :locals => { :view_bag => results }
37
+ end
38
+
39
+ get "/" do
40
+ results[:message] = nil
41
+ erb :welcome, :locals => { :view_bag => results }
42
+ end
43
+
44
+ get '/client_credentials' do
45
+ results[:auth_type] = :client_credentials
46
+ results[:message] = nil
47
+
48
+ erb :client_credentials, :locals => { :view_bag => results }
49
+ end
50
+
51
+ get '/client_credentials/logout' do
52
+ session["ClientCredential"] = nil
53
+ results[:message] = nil
54
+ results[:auth_type] = :client_credentials
55
+ results[:userinfo] = nil
56
+
57
+ erb :client_credentials, :locals => { :view_bag => results }
58
+ end
59
+
60
+ get '/client_credentials/login' do
61
+ results[:auth_type] = :client_credentials
62
+ results[:message] = nil
63
+ connection = session["ClientCredential"]
64
+ results[:userinfo] = nil
65
+
66
+ if (connection.nil?)
67
+
68
+ # get new connection configuration
69
+ # YAML config object placed in yaml configuration files
70
+ config = YAML.load_file('config/clientcredential_config.yml');
71
+
72
+ if (!config || config.nil?)
73
+ results[:message] = "Unable to load configuration settings from file (config/clientcredential_config.yml)"
74
+ else
75
+ begin
76
+ clientcredential_config = Adp::Connection::ClientCredentialConfiguration.new(config);
77
+
78
+ connection = Adp::Connection::ApiConnectionFactory::createConnection(clientcredential_config)
79
+
80
+ connection.connect();
81
+
82
+ if (!connection.is_connected_indicator?)
83
+ results[:message] = "Error attempting to establish a connection"
84
+ Log.error "Not connected"
85
+ else
86
+ Log.debug("Connected and ready for getting data");
87
+ session["ClientCredential"] = connection;
88
+ end
89
+ end
90
+ end
91
+ end
92
+ erb :client_credentials, :locals => { :view_bag => results }
93
+ end
94
+
95
+ get '/authorization_code' do
96
+ results[:message] = nil
97
+ results[:auth_type] = :authorization_code
98
+ erb :authorization_code, :locals => { :view_bag => results}
99
+ end
100
+
101
+ get '/authorization_code/logout' do
102
+ session["AuthorizationCode"] = nil
103
+ results[:message] = nil
104
+ results[:auth_type] = :authorization_code
105
+ results[:userinfo] = nil
106
+
107
+ erb :authorization_code, :locals => { :view_bag => results }
108
+ end
109
+
110
+ get '/authorization_code/login' do
111
+ connection = session["AuthorizationCode"]
112
+ results[:message] = nil
113
+ authorizationurl = nil
114
+ results[:userinfo] = nil
115
+
116
+ if (connection.nil?)
117
+
118
+ # get new connection configuration
119
+ # YAML config object placed in yaml configuration files
120
+ config = YAML.load_file('config/authorizationcode_config.yml');
121
+
122
+ if (config.nil? || !config) then
123
+ results[:message] = "Unable to load configuration settings from file (config/authorizationcode_config.yml)"
124
+ else
125
+ begin
126
+ authorizationcode_config = Adp::Connection::AuthorizationCodeConfiguration.new(config);
127
+
128
+ Log.debug("Configuration from file was #{authorizationcode_config}")
129
+ connection = Adp::Connection::ApiConnectionFactory::createConnection(authorizationcode_config)
130
+
131
+ Log.debug("Connection object was #{connection}")
132
+ session["AuthorizationCode"] = connection;
133
+ end
134
+ end
135
+ end
136
+
137
+ authorizationurl = connection.get_authorization_url
138
+
139
+ Log.debug("Redirecting to authorizationurl #{authorizationurl} from connection #{connection}")
140
+
141
+ results[:auth_type] = :authorization_code
142
+ results[:authorizationurl] = authorizationurl
143
+
144
+ redirect authorizationurl unless authorizationurl.nil?
145
+
146
+ erb :authorization_code, :locals => { :view_bag => results}
147
+ end
148
+
149
+ get '/callback' do
150
+ results[:auth_type] = :authorization_code
151
+ results[:message] = nil
152
+
153
+ if !params[:error].nil?
154
+ results[:message] = "Callback Error: #{params[:error]}"
155
+ else
156
+ if params[:code].nil?
157
+ results[:message] = "Callback Error: Unauthorized"
158
+ else
159
+ connection = session["AuthorizationCode"]
160
+ unless connection.nil?
161
+ connection.connection_configuration.authorizationCode = params[:code]
162
+ Log.debug("Got authorization code #{connection.connection_configuration.authorizationCode}")
163
+ end
164
+ end
165
+ end
166
+ Log.debug("Back to callback with #{params[:code]}")
167
+ erb :authorization_code, :locals => { :view_bag => results}
168
+ end
169
+
170
+ get '/authorization_code/get_token' do
171
+ results[:auth_type] = :authorization_code
172
+ results[:message] = nil
173
+ results[:userinfo] = nil
174
+ connection = session["AuthorizationCode"]
175
+
176
+ begin
177
+ unless connection.nil? || connection.connection_configuration.authorizationCode.nil?
178
+ connection.connect()
179
+ session["AuthorizationCode"] = connection
180
+ end
181
+ rescue Adp::Connection::ConnectionException
182
+ e = env['sinatra.error']
183
+ results[:message] = "Connection error: The requested token could not be retrieved"
184
+ end
185
+
186
+ erb :authorization_code, :locals => { :view_bag => results}
187
+ end
188
+
189
+ get '/authorization_code/get_userinfo' do
190
+ results[:auth_type] = :authorization_code
191
+ results[:message] = nil
192
+ connection = session["AuthorizationCode"]
193
+
194
+ begin
195
+ Log.debug("Do we have a connection object? #{connection}")
196
+ unless connection.nil? || connection.connection_configuration.authorizationCode.nil?
197
+ Log.debug("Check if we are connected: #{connection.access_token}")
198
+ if (connection.is_connected_indicator?)
199
+ Log.debug("Getting helper object")
200
+ helper = Adp::Product::Userinfo::Helper.new(connection)
201
+ Log.debug("getting userinfo using helper object")
202
+ json_data = helper.get_user_info()
203
+ results[:userinfo] = Adp::Product::DTO::Userinfo.new(json_data)
204
+
205
+ Log.debug("Got user info #{json_data}")
206
+ end
207
+ end
208
+ Log.debug("Done getting userinfo #{results[:userinfo]}")
209
+ rescue Adp::Connection::ConnectionException
210
+ e = env['sinatra.error']
211
+ results[:message] = "Connection error: #{e}"
212
+ end
213
+
214
+ erb :authorization_code, :locals => { :view_bag => results}
215
+ end
216
+ end