oxd-ruby 0.1.7 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: becb5e6cf7b08da462269a04cb94f5df77c9a903
4
- data.tar.gz: e39d828b7f16eaf9a0a70e1eb70828065bc1c603
3
+ metadata.gz: 3c927e7af3f706adb71804447f38b290df3cb5b1
4
+ data.tar.gz: cf118779fe069f932110fc38477e990adddd6fb1
5
5
  SHA512:
6
- metadata.gz: 785054ee62b5971ac043b85987086f115c5d23052556182649b78ff34e335f307a6bd36c265b99c3c997079ef9458f049585c1a69bfbe3b6e1db0d947c7a0df6
7
- data.tar.gz: 9d21df5d8571a358ef2bc5f56c22b1c384fb4adde6cbca19cf1c045880fa942b7ec0b2b7a1a6734da17136da7b80abc89c00f654dc3b3149bdd6b7a068563d75
6
+ metadata.gz: a8b71232f3ecb9c829eba9511ecf6232f7ba9429e18e1afc7f69b62b79aad9ad173e949baa2a3286c21e586f98f7c5b42e38a6408829fcd5371f6cd41f16d2f2
7
+ data.tar.gz: 116fc42fff057ff8840ecc90493fd1abf4bd978dfc9c065592d7f29a53b6d53801e39fd32646a897a786109d8dc8287cb5c18ba8d167c894bd9d3d66c2018858
data/.gitignore CHANGED
@@ -6,4 +6,4 @@
6
6
  /doc/
7
7
  /pkg/
8
8
  /spec/reports/
9
- /tmp/
9
+ /tmp/
@@ -1,6 +1,10 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.1.8] - 2017-05-16
5
+ ### Added
6
+ - support for oxd-to-http
7
+
4
8
  ## [0.1.7] - 2017-03-10
5
9
  ### Added
6
10
  - `state` parameter in `get_tokens_by_code` command
@@ -34,4 +38,4 @@ All notable changes to this project will be documented in this file.
34
38
  - support for oxd-server 2.4.4
35
39
  - support for UMA
36
40
  - `config.op_host` parameter in configuration
37
- - added scopes "uma_protection","uma_authorization"
41
+ - added scopes "uma_protection","uma_authorization"
data/README.md CHANGED
@@ -24,7 +24,7 @@ Oxd-server needs to be running on your machine to connect with OP.
24
24
  To install gem, add this line to your application's Gemfile:
25
25
 
26
26
  ```ruby
27
- gem 'oxd-ruby', '~> 0.1.7'
27
+ gem 'oxd-ruby', '~> 0.1.8'
28
28
  ```
29
29
 
30
30
  Run bundle command to install it:
@@ -33,7 +33,7 @@ gem "twitter-bootstrap-rails"
33
33
  # Use Capistrano for deployment
34
34
  # gem 'capistrano-rails', group: :development
35
35
 
36
- gem 'oxd-ruby', '~> 0.1.7'
36
+ gem 'oxd-ruby', '~> 0.1.8'
37
37
 
38
38
  group :development, :test do
39
39
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
@@ -46,4 +46,4 @@ group :development do
46
46
 
47
47
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
48
48
  gem 'spring'
49
- end
49
+ end
@@ -16,6 +16,7 @@ module Oxd
16
16
 
17
17
  # @return [String] oxd_id of the registered website
18
18
  # method to register the website and generate a unique ID for that website
19
+ # works with both oxd-to-http and oxd-server
19
20
  def register_site
20
21
  if(!@configuration.oxd_id.empty?) # Check if client is already registered
21
22
  return @configuration.oxd_id
@@ -38,7 +39,7 @@ module Oxd
38
39
  "client_secret"=> @configuration.client_secret,
39
40
  "client_id"=> @configuration.client_id
40
41
  }
41
- request
42
+ request('register-site')
42
43
  @configuration.oxd_id = getResponseData['oxd_id']
43
44
  end
44
45
  end
@@ -51,6 +52,7 @@ module Oxd
51
52
  # @param acr_values [Array] OPTIONAL, list of acr values in the order of priority
52
53
  # @return [String] authorization_url
53
54
  # method to get authorization url that the user must be redirected to for authorization and authentication
55
+ # works with both oxd-to-http and oxd-server
54
56
  def get_authorization_url(acr_values = [""])
55
57
  @command = 'get_authorization_url'
56
58
  @params = {
@@ -58,7 +60,7 @@ module Oxd
58
60
  "prompt" => @configuration.prompt,
59
61
  "acr_values" => acr_values || @configuration.acr_values
60
62
  }
61
- request
63
+ request('get-authorization-url')
62
64
  getResponseData['authorization_url']
63
65
  end
64
66
 
@@ -66,6 +68,7 @@ module Oxd
66
68
  # @param state [String] state obtained from the authorization url callback
67
69
  # @return [Hash] {:access_token, :id_token}
68
70
  # method to retrieve access token. It is called after the user authorizes by visiting the authorization url.
71
+ # works with both oxd-to-http and oxd-server
69
72
  def get_tokens_by_code( code,state )
70
73
  if (code.empty?)
71
74
  logger(:log_msg => "Empty/Wrong value in place of code.")
@@ -76,7 +79,7 @@ module Oxd
76
79
  "code" => code,
77
80
  "state" => state
78
81
  }
79
- request
82
+ request('get-tokens-by-code')
80
83
  @configuration.id_token = getResponseData['id_token']
81
84
  getResponseData['access_token']
82
85
  end
@@ -84,6 +87,7 @@ module Oxd
84
87
  # @param access_token [String] access token recieved from the get_tokens_by_code command
85
88
  # @return [String] user data claims that are returned by the OP
86
89
  # get the information about the user using the access token obtained from the OP
90
+ # works with both oxd-to-http and oxd-server
87
91
  def get_user_info(access_token)
88
92
  if access_token.empty?
89
93
  logger(:log_msg => "Empty access code sent for get_user_info", :error => "Empty access code")
@@ -93,7 +97,7 @@ module Oxd
93
97
  "oxd_id" => @configuration.oxd_id,
94
98
  "access_token" => access_token
95
99
  }
96
- request
100
+ request('get-user-info')
97
101
  getResponseData['claims']
98
102
  end
99
103
 
@@ -101,6 +105,7 @@ module Oxd
101
105
  # @param session_state [String] OPTIONAL, session state obtained from the authorization url callback
102
106
  # @return [String] uri
103
107
  # method to retrieve logout url from OP. User must be redirected to this url to perform logout
108
+ # works with both oxd-to-http and oxd-server
104
109
  def get_logout_uri( state = nil, session_state = nil)
105
110
  @command = 'get_logout_uri'
106
111
  @params = {
@@ -110,7 +115,7 @@ module Oxd
110
115
  "state" => state,
111
116
  "session_state" => session_state
112
117
  }
113
- request
118
+ request('logout')
114
119
  getResponseData['uri']
115
120
  #@configuration.oxd_id = "" #unset oxd_id after logout
116
121
  end
@@ -118,6 +123,7 @@ module Oxd
118
123
  # @return [Boolean] status - if site registration was updated successfully or not
119
124
  # method to update the website's information with OpenID Provider.
120
125
  # This should be called after changing the values in the oxd_config file.
126
+ # works with both oxd-to-http and oxd-server
121
127
  def update_site_registration
122
128
  @command = 'update_site_registration'
123
129
  @params = {
@@ -136,7 +142,7 @@ module Oxd
136
142
  "client_secret_expires_at" => 3080736637943,
137
143
  "client_logout_uris"=> @configuration.client_logout_uris
138
144
  }
139
- request
145
+ request('update-site-registration')
140
146
  if @response_object['status'] == "ok"
141
147
  @configuration.oxd_id = getResponseData['oxd_id']
142
148
  return true
@@ -145,4 +151,4 @@ module Oxd
145
151
  end
146
152
  end
147
153
  end
148
- end
154
+ end
@@ -1,5 +1,8 @@
1
1
  require 'socket'
2
2
  require 'ipaddr'
3
+ require 'net/http'
4
+ require 'json'
5
+ require 'uri'
3
6
 
4
7
  # @author Inderpal Singh
5
8
  # @note supports oxd-version 2.4.4
@@ -55,38 +58,68 @@ module Oxd
55
58
  if(socket.close)
56
59
  logger(:log_msg => "Client: oxd_socket_connection : disconnected.", :error => "")
57
60
  end
61
+ #logger(:log_msg => response)
62
+ #abort
58
63
  return response
59
64
  end
65
+
66
+ # method to communicate with the oxD-to-http server
67
+ # @param request [JSON] representation of the JSON command string
68
+ # @param char_count [Integer] number of characters to read from response
69
+ # @return response from the oxD-to-http server
70
+ def oxd_http_request(requst, command = "")
71
+ uri = URI.parse("https://127.0.0.1/"+command)
72
+ http = Net::HTTP.new("127.0.0.1", 8443)
73
+ http.use_ssl = true
74
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
75
+ request = Net::HTTP::Post.new(uri.request_uri)
76
+ request.add_field('Content-Type', 'application/json')
77
+ request.body = requst
78
+ response = http.request(request)
79
+ response2 = response.body
80
+ return response2
81
+ end
60
82
 
61
- # method to send commands to the oxD server and to recieve the response via {#oxd_socket_request}
83
+ # @param comm [String] command string for oxd-to-http
84
+ # method to send commands to the oxD server and oxd-to-http and to recieve the response via {#oxd_socket_request}
62
85
  # @return [JSON] @response_object : response from the oxd server in JSON form
63
- def request
86
+ def request(comm = "")
87
+
64
88
  uri = URI.parse(@configuration.authorization_redirect_uri)
65
89
  logger(:log_msg => "Please enable SSL on your website or check URIs in Oxd configuration.") if (uri.scheme != 'https')
66
90
  validate_command
67
- jsondata = getData.to_json
68
- if(!is_json? (jsondata))
69
- logger(:log_msg => "Sending parameters must be JSON. Exiting process.")
70
- end
71
- length = jsondata.length
72
- if( length <= 0 )
73
- logger(:log_msg => "JSON data length must be more than zero. Exiting process.")
91
+
92
+ if(@configuration.oxd_host_port == 8099)
93
+ jsondata = getData.to_json
94
+ if(!is_json? (jsondata))
95
+ logger(:log_msg => "Sending parameters must be JSON. Exiting process.")
96
+ end
97
+ length = jsondata.length
98
+ if( length <= 0 )
99
+ logger(:log_msg => "JSON data length must be more than zero. Exiting process.")
100
+ else
101
+ length = length <= 999 ? sprintf('0%d', length) : length
102
+ end
103
+ @response_json = oxd_socket_request((length.to_s + jsondata).encode("UTF-8"))
104
+ @response_json.sub!(@response_json[0..3], "")
74
105
  else
75
- length = length <= 999 ? sprintf('0%d', length) : length
106
+ jsondata = getData2.to_json
107
+ @response_json = oxd_http_request(jsondata, comm)
76
108
  end
77
- @response_json = oxd_socket_request((length.to_s + jsondata).encode("UTF-8"))
78
- @response_json.sub!(@response_json[0..3], "")
109
+
79
110
 
80
111
  if (@response_json)
81
112
  response = JSON.parse(@response_json)
82
113
  if (response['status'] == 'error')
83
114
  logger(:log_msg => "OxD Server Error : #{response['data']['error_description']}")
84
- elsif (response['status'] == 'ok')
115
+ elsif (response['status'] == 'ok')
116
+
85
117
  @response_object = JSON.parse(@response_json)
86
118
  end
87
119
  else
88
120
  logger(:log_msg => "Response is empty. Exiting process.")
89
121
  end
122
+
90
123
  return @response_object
91
124
  end
92
125
 
@@ -112,6 +145,11 @@ module Oxd
112
145
  @data = {'command' => @command, 'params' => @params}
113
146
  return @data
114
147
  end
148
+
149
+ def getData2
150
+ @data = @params
151
+ return @data
152
+ end
115
153
 
116
154
  # checks whether the passed string is in JSON format or not
117
155
  # @param string_to_validate [String]
@@ -137,4 +175,4 @@ module Oxd
137
175
  raise (args[:error] || args[:log_msg]) if args[:error] != ""
138
176
  end
139
177
  end
140
- end
178
+ end
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module Oxd
3
- VERSION = "0.1.7"
3
+ VERSION = "0.1.8"
4
4
  end
@@ -21,4 +21,4 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec"
23
23
  spec.add_development_dependency "rspec-rails"
24
- end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxd-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - inderpal6785
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -174,10 +174,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
174
  version: '0'
175
175
  requirements: []
176
176
  rubyforge_project:
177
- rubygems_version: 2.4.6
177
+ rubygems_version: 2.6.8
178
178
  signing_key:
179
179
  specification_version: 4
180
180
  summary: Ruby Client Library for Oxd Server - OpenID Connect Client RP Middleware,
181
181
  which organizes authentication and registration of users.
182
182
  test_files: []
183
- has_rdoc: