oxd-ruby 0.1.8 → 0.1.9
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 +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +107 -31
- data/demosite/Gemfile +2 -1
- data/demosite/Gemfile.lock +197 -0
- data/demosite/app/controllers/application_controller.rb +32 -1
- data/demosite/app/controllers/home_controller.rb +48 -6
- data/demosite/app/controllers/uma_controller.rb +15 -15
- data/demosite/app/views/home/index.html.erb +115 -37
- data/demosite/app/views/uma/index.html.erb +42 -40
- data/demosite/config/initializers/oxd_config.rb +15 -9
- data/demosite/config/routes.rb +6 -2
- data/lib/generators/oxd/templates/oxd_config.rb +10 -4
- data/lib/oxd-ruby.rb +1 -1
- data/lib/oxd/client_oxd_commands.rb +147 -43
- data/lib/oxd/config.rb +28 -11
- data/lib/oxd/oxd_connector.rb +16 -10
- data/lib/oxd/uma_commands.rb +47 -43
- data/lib/oxd/version.rb +1 -1
- metadata +3 -2
data/lib/oxd/oxd_connector.rb
CHANGED
@@ -5,7 +5,7 @@ require 'json'
|
|
5
5
|
require 'uri'
|
6
6
|
|
7
7
|
# @author Inderpal Singh
|
8
|
-
# @note supports oxd-version
|
8
|
+
# @note supports oxd-version 3.1.1
|
9
9
|
module Oxd
|
10
10
|
|
11
11
|
# A class which takes care of the socket communication with oxD Server.
|
@@ -19,7 +19,8 @@ module Oxd
|
|
19
19
|
@data = Hash.new
|
20
20
|
@params = Hash.new
|
21
21
|
@response_data = Hash.new
|
22
|
-
@configuration = Oxd.config
|
22
|
+
@configuration = Oxd.config
|
23
|
+
|
23
24
|
logger(:log_msg => "Problem with json data : authorization_redirect_uri can't be blank") if @configuration.authorization_redirect_uri.empty?
|
24
25
|
logger(:log_msg => "#{@configuration.oxd_host_ip} is not a valid IP address") if (IPAddr.new(@configuration.oxd_host_ip) rescue nil).nil?
|
25
26
|
logger(:log_msg => "#{@configuration.oxd_host_port} is not a valid port for socket. Port must be integer and between from 0 to 65535") if (!@configuration.oxd_host_port.is_a?(Integer) || (@configuration.oxd_host_port < 0 && @configuration.oxd_host_port > 65535))
|
@@ -27,7 +28,7 @@ module Oxd
|
|
27
28
|
|
28
29
|
# Checks the validity of command that is to be passed to oxd-server
|
29
30
|
def validate_command
|
30
|
-
command_types = ['get_authorization_url','update_site_registration',
|
31
|
+
command_types = ['setup_client', 'get_client_token', 'get_authorization_url','update_site_registration','get_tokens_by_code','get_access_token_by_refresh_token', 'get_user_info', 'register_site', 'get_logout_uri','get_authorization_code','uma_rs_protect','uma_rs_check_access','uma_rp_get_rpt','uma_rp_get_claims_gathering_url']
|
31
32
|
if (!command_types.include?(@command))
|
32
33
|
logger(:log_msg => "Command: #{@command} does not exist! Exiting process.")
|
33
34
|
end
|
@@ -64,19 +65,25 @@ module Oxd
|
|
64
65
|
end
|
65
66
|
|
66
67
|
# method to communicate with the oxD-to-http server
|
67
|
-
# @param
|
68
|
-
# @param char_count [Integer] number of characters to read from response
|
68
|
+
# @param request_params [JSON] representation of the JSON command string
|
69
69
|
# @return response from the oxD-to-http server
|
70
|
-
def oxd_http_request(
|
70
|
+
def oxd_http_request(request_params, command = "")
|
71
71
|
uri = URI.parse("https://127.0.0.1/"+command)
|
72
72
|
http = Net::HTTP.new("127.0.0.1", 8443)
|
73
73
|
http.use_ssl = true
|
74
74
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
75
75
|
request = Net::HTTP::Post.new(uri.request_uri)
|
76
|
+
|
76
77
|
request.add_field('Content-Type', 'application/json')
|
77
|
-
|
78
|
+
|
79
|
+
if(@configuration.protection_access_token.present?)
|
80
|
+
request.add_field('Authorization','Bearer '+@configuration.protection_access_token)
|
81
|
+
end
|
82
|
+
request.body = request_params
|
83
|
+
logger(:log_msg => "Sending oxd_http_request command #{command} with data #{request_params.inspect}", :error => "")
|
78
84
|
response = http.request(request)
|
79
85
|
response2 = response.body
|
86
|
+
logger(:log_msg => "oxd_http_request response #{response2}", :error => "")
|
80
87
|
return response2
|
81
88
|
end
|
82
89
|
|
@@ -89,7 +96,7 @@ module Oxd
|
|
89
96
|
logger(:log_msg => "Please enable SSL on your website or check URIs in Oxd configuration.") if (uri.scheme != 'https')
|
90
97
|
validate_command
|
91
98
|
|
92
|
-
if(@configuration.
|
99
|
+
if(@configuration.connection_type == 'local')
|
93
100
|
jsondata = getData.to_json
|
94
101
|
if(!is_json? (jsondata))
|
95
102
|
logger(:log_msg => "Sending parameters must be JSON. Exiting process.")
|
@@ -163,8 +170,7 @@ module Oxd
|
|
163
170
|
end
|
164
171
|
|
165
172
|
# Logs server response and errors to log file
|
166
|
-
# @param
|
167
|
-
# @param error [Hash] error message to print in log file
|
173
|
+
# @param args [Hash] {:log_msg, :error} response to print in log file and raise error
|
168
174
|
# @raise RuntimeError
|
169
175
|
def logger(args={})
|
170
176
|
# Initialize Log file
|
data/lib/oxd/uma_commands.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# @author Inderpal Singh
|
2
|
-
# @note supports oxd-version
|
2
|
+
# @note supports oxd-version 3.1.1
|
3
3
|
module Oxd
|
4
4
|
|
5
5
|
require 'json'
|
@@ -21,8 +21,8 @@ module Oxd
|
|
21
21
|
# condition2 = {:httpMethods => ["PUT", "POST"], :scopes => ["http://photoz.example.com/dev/actions/all","http://photoz.example.com/dev/actions/add"],:ticketScopes => ["http://photoz.example.com/dev/actions/add"]}
|
22
22
|
# uma_add_resource("/photo", condition1, condition2)
|
23
23
|
# combines multiple resources into @resources array to pass to uma_rs_protect method
|
24
|
-
def uma_add_resource(path, *conditions)
|
25
|
-
@resources.push({:path => path, :conditions => conditions})
|
24
|
+
def uma_add_resource(path, *conditions)
|
25
|
+
@resources.push({:path => path, :conditions => conditions})
|
26
26
|
end
|
27
27
|
|
28
28
|
# @return [STRING] oxd_id
|
@@ -30,28 +30,45 @@ module Oxd
|
|
30
30
|
# method to protect resources with UMA resource server
|
31
31
|
def uma_rs_protect
|
32
32
|
logger(:log_msg => "Please set resources with uma_add_resource(path, *conditions) method first.") if(@resources.nil?)
|
33
|
+
logger(:log_msg => "UMA configuration #{@configuration}", :error => '')
|
33
34
|
@command = 'uma_rs_protect'
|
34
35
|
@params = {
|
35
36
|
"oxd_id" => @configuration.oxd_id,
|
36
|
-
"resources" => @resources
|
37
|
+
"resources" => @resources,
|
38
|
+
"protection_access_token" => @configuration.protection_access_token
|
37
39
|
}
|
38
|
-
request
|
40
|
+
request('uma-rs-protect')
|
39
41
|
getResponseData['oxd_id']
|
40
42
|
end
|
41
43
|
|
42
|
-
# @param
|
43
|
-
# @
|
44
|
-
# @
|
44
|
+
# @param claim_token [STRING] OPTIONAL
|
45
|
+
# @param claim_token_format [STRING] OPTIONAL
|
46
|
+
# @param pct [STRING] OPTIONAL
|
47
|
+
# @param rpt [STRING] OPTIONAL
|
48
|
+
# @param scope [STRING] OPTIONAL
|
49
|
+
# @param state [STRING] OPTIONAL, state that is returned from uma_rp_get_claims_gathering_url command
|
50
|
+
# @return [Hash] response data (access_token, token_type, pct, upgraded)
|
45
51
|
# method for obtaining RPT to gain access to protected resources at the UMA resource server
|
46
|
-
def uma_rp_get_rpt(
|
47
|
-
logger(:log_msg => "Wrong value for force_new param. #{force_new.kind_of?(TrueClass)}") if(force_new.kind_of?(TrueClass) || force_new.kind_of?(FalseClass))
|
52
|
+
def uma_rp_get_rpt( claim_token = nil, claim_token_format = nil, pct = nil, rpt = nil, scope = nil, state = nil )
|
48
53
|
@command = 'uma_rp_get_rpt'
|
49
54
|
@params = {
|
50
55
|
"oxd_id" => @configuration.oxd_id,
|
51
|
-
"
|
56
|
+
"ticket" => @configuration.ticket,
|
57
|
+
"claim_token" => claim_token,
|
58
|
+
"claim_token_format" => claim_token_format,
|
59
|
+
"pct" => pct,
|
60
|
+
"rpt" => (!rpt.nil?)? rpt : @configuration.rpt,
|
61
|
+
"scope" => scope,
|
62
|
+
"state" => state,
|
63
|
+
"protection_access_token" => @configuration.protection_access_token
|
52
64
|
}
|
53
|
-
request
|
54
|
-
|
65
|
+
request('uma-rp-get-rpt')
|
66
|
+
|
67
|
+
if getResponseData['error'] == 'need_info' && !getResponseData['details']['ticket'].empty?
|
68
|
+
@configuration.ticket = getResponseData['details']['ticket']
|
69
|
+
end
|
70
|
+
|
71
|
+
getResponseData
|
55
72
|
end
|
56
73
|
|
57
74
|
# @param path [STRING] REQUIRED
|
@@ -67,47 +84,34 @@ module Oxd
|
|
67
84
|
"oxd_id" => @configuration.oxd_id,
|
68
85
|
"rpt" => @configuration.rpt,
|
69
86
|
"path" => path,
|
70
|
-
"http_method" => http_method
|
87
|
+
"http_method" => http_method,
|
88
|
+
"protection_access_token" => @configuration.protection_access_token
|
71
89
|
}
|
72
|
-
request
|
90
|
+
request('uma-rs-check-access')
|
73
91
|
if getResponseData['access'] == 'denied' && !getResponseData['ticket'].empty?
|
74
92
|
@configuration.ticket = getResponseData['ticket']
|
75
93
|
elsif getResponseData['access'] == 'granted'
|
76
94
|
@configuration.ticket = ""
|
77
95
|
end
|
78
96
|
getResponseData
|
79
|
-
end
|
80
|
-
|
81
|
-
# @return [String] oxd_id
|
82
|
-
# @note This method should always be called after uma_rp_get_rpt and uma_rs_check_access methods
|
83
|
-
# Method to authorize generated RPT using oxd_id and ticket.
|
84
|
-
def uma_rp_authorize_rpt
|
85
|
-
@command = 'uma_rp_authorize_rpt'
|
86
|
-
@params = {
|
87
|
-
"oxd_id" => @configuration.oxd_id,
|
88
|
-
"rpt" => @configuration.rpt,
|
89
|
-
"ticket" => @configuration.ticket
|
90
|
-
}
|
91
|
-
request
|
92
|
-
getResponseData['oxd_id']
|
93
97
|
end
|
94
98
|
|
95
|
-
# @param
|
96
|
-
# @return [
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@command = 'uma_rp_get_gat'
|
99
|
+
# @param claims_redirect_uri [STRING] REQUIRED
|
100
|
+
# @return [Hash] response data (url, state)
|
101
|
+
# method to check if we have permission to access particular resource or not
|
102
|
+
def uma_rp_get_claims_gathering_url( claims_redirect_uri )
|
103
|
+
if (claims_redirect_uri.empty?)
|
104
|
+
logger(:log_msg => "Empty/Wrong value in place of claims_redirect_uri.")
|
105
|
+
end
|
106
|
+
@command = 'uma_rp_get_claims_gathering_url'
|
104
107
|
@params = {
|
105
108
|
"oxd_id" => @configuration.oxd_id,
|
106
|
-
"
|
109
|
+
"ticket" => @configuration.ticket,
|
110
|
+
"claims_redirect_uri" => claims_redirect_uri,
|
111
|
+
"protection_access_token" => @configuration.protection_access_token
|
107
112
|
}
|
108
|
-
request
|
109
|
-
|
110
|
-
|
111
|
-
end
|
113
|
+
request('uma-rp-get-claims-gathering-url')
|
114
|
+
getResponseData
|
115
|
+
end
|
112
116
|
end
|
113
117
|
end
|
data/lib/oxd/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- inderpal6785
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- Rakefile
|
85
85
|
- demosite/.gitignore
|
86
86
|
- demosite/Gemfile
|
87
|
+
- demosite/Gemfile.lock
|
87
88
|
- demosite/README.md
|
88
89
|
- demosite/Rakefile
|
89
90
|
- demosite/app/assets/images/.keep
|