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.
@@ -5,7 +5,7 @@ require 'json'
5
5
  require 'uri'
6
6
 
7
7
  # @author Inderpal Singh
8
- # @note supports oxd-version 2.4.4
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', 'get_tokens_by_code','get_user_info', 'register_site', 'get_logout_uri','get_authorization_code','uma_rs_protect','uma_rs_check_access','uma_rp_get_rpt','uma_rp_authorize_rpt','uma_rp_get_gat']
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 request [JSON] representation of the JSON command string
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(requst, command = "")
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
- request.body = requst
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.oxd_host_port == 8099)
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 log_msg [Hash] response to print in log file
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
@@ -1,5 +1,5 @@
1
1
  # @author Inderpal Singh
2
- # @note supports oxd-version 2.4.4
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 force_new [BOOLEAN] REQUIRED
43
- # @return [STRING] RPT
44
- # @raise RuntimeError if force_new param is not boolean
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(force_new)
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
- "force_new" => force_new
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
- @configuration.rpt = getResponseData['rpt']
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 scopes [Array] REQUIRED
96
- # @return [String] rpt
97
- # @example
98
- # scopes = ["http://photoz.example.com/dev/actions/add","http://photoz.example.com/dev/actions/view"]
99
- # uma_rp_get_gat(scopes)
100
- # method to obtain GAT (Gluu Access Token)
101
- def uma_rp_get_gat(scopes)
102
- logger(:log_msg => "Invalid value for scopes argument.") if(!scopes.kind_of? Array)
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
- "scopes" => scopes
109
+ "ticket" => @configuration.ticket,
110
+ "claims_redirect_uri" => claims_redirect_uri,
111
+ "protection_access_token" => @configuration.protection_access_token
107
112
  }
108
- request
109
- logger(:log_msg => "Invalid GAT recieved : #{getResponseData['rpt']}") if(!getResponseData['rpt'].match(/gat_/)[0])
110
- getResponseData['rpt']
111
- end
113
+ request('uma-rp-get-claims-gathering-url')
114
+ getResponseData
115
+ end
112
116
  end
113
117
  end
@@ -1,4 +1,4 @@
1
1
  # Gem version
2
2
  module Oxd
3
- VERSION = "0.1.8"
3
+ VERSION = "0.1.9"
4
4
  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.8
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-05-17 00:00:00.000000000 Z
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