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.
@@ -2,18 +2,24 @@
2
2
  Oxd.configure do |config|
3
3
  config.oxd_host_ip = '127.0.0.1'
4
4
  config.oxd_host_port = 8099
5
- config.op_host = "https://ce-dev2.gluu.org"
6
- config.authorization_redirect_uri = "https://oxd-rails.com/login"
7
- config.logout_redirect_uri = "https://oxd-rails.com/logout"
8
- config.post_logout_redirect_uri = "https://oxd-rails.com/"
9
- config.scope = [ "openid", "profile","uma_protection","uma_authorization" ]
5
+ config.op_host = "https://ce-dev2.gluu.org"
6
+ config.client_id = ""
7
+ config.client_secret = ""
8
+ config.client_name = "Gluu Oxd Sample Client"
9
+ config.authorization_redirect_uri = "https://oxd-rails-app.com/login"
10
+ config.logout_redirect_uri = "https://oxd-rails-app.com/logout"
11
+ config.post_logout_redirect_uri = "https://oxd-rails-app.com/"
12
+ config.scope = ["openid","profile", "email", "uma_protection","uma_authorization"]
13
+ config.grant_types = []
10
14
  config.application_type = "web"
15
+ config.response_types = ["code"]
16
+ config.acr_values = ["basic"]
11
17
  config.client_jwks_uri = ""
12
18
  config.client_token_endpoint_auth_method = ""
13
19
  config.client_request_uris = []
14
20
  config.contacts = ["example-email@gmail.com"]
15
- config.grant_types = []
16
- config.response_types = ["code"]
17
- config.acr_values = ["basic"]
18
- config.client_logout_uris = ['https://oxd-rails.com/logout']
21
+ config.client_logout_uris = ['https://oxd-rails-app.com/logout']
22
+ config.oxd_host = "https://127.0.0.1:8443"
23
+ config.connection_type = "web"
24
+ config.dynamic_registration = true
19
25
  end
@@ -1,17 +1,21 @@
1
1
  Rails.application.routes.draw do
2
2
 
3
3
  root 'home#index'
4
+ get '/setup_client' => 'home#setup_client'
5
+ get '/get_client_token' => 'home#get_client_token'
6
+ get '/update_registration' => 'home#update_registration'
4
7
  get '/register_site' => 'home#register_site'
5
8
  get '/login' => 'home#login'
6
9
  get '/logout' => 'home#logout'
10
+ get '/clear_data' => 'home#clear_data'
7
11
 
8
12
  resources :uma do
9
13
  collection do
10
14
  get 'protect_resources'
15
+ get 'get_client_token'
11
16
  get 'get_rpt'
12
17
  get 'check_access'
13
- get 'authorize_rpt'
14
- get 'get_gat'
18
+ get 'get_claims_gathering_url'
15
19
  end
16
20
  end
17
21
 
@@ -3,17 +3,23 @@ Oxd.configure do |config|
3
3
  config.oxd_host_ip = '127.0.0.1'
4
4
  config.oxd_host_port = 8099
5
5
  config.op_host = "https://your.openid.provider.com"
6
+ config.client_id = ""
7
+ config.client_secret = ""
8
+ config.client_name = "Gluu Oxd Sample Client"
6
9
  config.authorization_redirect_uri = "https://domain.example.com/callback"
7
10
  config.logout_redirect_uri = "https://domain.example.com/callback2"
8
11
  config.post_logout_redirect_uri = "https://domain.example.com/logout"
9
- config.scope = ["openid","profile","uma_protection","uma_authorization"]
12
+ config.scope = ["openid","profile", "email", "uma_protection","uma_authorization"]
13
+ config.grant_types = []
10
14
  config.application_type = "web"
15
+ config.response_types = ["code"]
16
+ config.acr_values = ["basic"]
11
17
  config.client_jwks_uri = ""
12
18
  config.client_token_endpoint_auth_method = ""
13
19
  config.client_request_uris = []
14
20
  config.contacts = ["example-email@gmail.com"]
15
- config.grant_types = []
16
- config.response_types = ["code"]
17
- config.acr_values = ["basic"]
18
21
  config.client_logout_uris = ['https://domain.example.com/logout']
22
+ config.oxd_host = ""
23
+ config.connection_type = "local"
24
+ config.dynamic_registration = true
19
25
  end
@@ -6,7 +6,7 @@ require 'oxd/uma_commands'
6
6
 
7
7
  # @author Inderpal Singh
8
8
  # Oxd Module namespace
9
- # oxd_version 2.4.4
9
+ # oxd_version 3.1.1
10
10
  module Oxd
11
11
 
12
12
  end
@@ -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'
@@ -14,52 +14,128 @@ module Oxd
14
14
  super
15
15
  end
16
16
 
17
+ # @return [String] oxd_id of the registered website
18
+ # method to setup the client and generate a Client ID, Client Secret for the site
19
+ # works with oxd-to-https and oxd-server
20
+ def setup_client
21
+ @command = 'setup_client'
22
+ @params = {
23
+ "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
24
+ "op_host" => @configuration.op_host,
25
+ "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
26
+ "application_type" => @configuration.application_type,
27
+ "response_types"=> @configuration.response_types,
28
+ "grant_types" => @configuration.grant_types,
29
+ "scope" => @configuration.scope,
30
+ "acr_values" => @configuration.acr_values,
31
+ "client_jwks_uri" => @configuration.client_jwks_uri,
32
+ "client_name" => @configuration.client_name,
33
+ "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
34
+ "client_request_uris" => @configuration.client_request_uris,
35
+ "client_logout_uris"=> @configuration.client_logout_uris,
36
+ "client_sector_identifier_uri" => @configuration.client_sector_identifier_uri,
37
+ "contacts" => @configuration.contacts,
38
+ "ui_locales" => @configuration.ui_locales,
39
+ "claims_locales" => @configuration.claims_locales,
40
+ "client_id" => @configuration.client_id,
41
+ "client_secret" => @configuration.client_secret,
42
+ "oxd_rp_programming_language" => 'ruby',
43
+ "protection_access_token" => @configuration.protection_access_token
44
+ }
45
+ request('setup-client')
46
+ @configuration.client_id = getResponseData['client_id']
47
+ @configuration.client_secret = getResponseData['client_secret']
48
+ @configuration.oxd_id = getResponseData['oxd_id']
49
+
50
+ end
51
+
17
52
  # @return [String] oxd_id of the registered website
18
53
  # method to register the website and generate a unique ID for that website
19
- # works with both oxd-to-http and oxd-server
20
- def register_site
54
+ # works with oxd-to-https and oxd-server
55
+ def register_site
21
56
  if(!@configuration.oxd_id.empty?) # Check if client is already registered
22
57
  return @configuration.oxd_id
23
58
  else
24
59
  @command = 'register_site'
25
60
  @params = {
26
- "op_host" => @configuration.op_host,
27
61
  "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
62
+ "op_host" => @configuration.op_host,
28
63
  "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
29
64
  "application_type" => @configuration.application_type,
30
- "acr_values" => @configuration.acr_values,
65
+ "response_types"=> @configuration.response_types,
66
+ "grant_types" => @configuration.grant_types,
31
67
  "scope" => @configuration.scope,
68
+ "acr_values" => @configuration.acr_values,
32
69
  "client_jwks_uri" => @configuration.client_jwks_uri,
33
70
  "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
34
71
  "client_request_uris" => @configuration.client_request_uris,
35
- "contacts" => @configuration.contacts,
36
- "grant_types" => @configuration.grant_types,
37
- "response_types"=> @configuration.response_types,
38
72
  "client_logout_uris"=> @configuration.client_logout_uris,
39
- "client_secret"=> @configuration.client_secret,
40
- "client_id"=> @configuration.client_id
73
+ "contacts" => @configuration.contacts,
74
+ "client_id" => @configuration.client_id,
75
+ "client_secret" => @configuration.client_secret,
76
+ "client_name" => @configuration.client_name,
77
+ "client_sector_identifier_uri" => @configuration.client_sector_identifier_uri,
78
+ "ui_locales" => @configuration.ui_locales,
79
+ "claims_locales" => @configuration.claims_locales,
80
+ "protection_access_token" => @configuration.protection_access_token
41
81
  }
42
82
  request('register-site')
83
+ logger(:log_msg => "OXD ID FROM setup_client : "+getResponseData['oxd_id'])
43
84
  @configuration.oxd_id = getResponseData['oxd_id']
44
85
  end
45
86
  end
46
87
 
47
- # @return [String] stored(in oxd_config) oxd_id of the registered website
48
- def getOxdId
49
- return @configuration.oxd_id
50
- end
51
-
88
+ # @return [STRING] access_token
89
+ # method to generate the protection access token
90
+ # obtained access token is passed as protection_access_token to all further calls to oxd-https-extension
91
+ def get_client_token
92
+ @command = 'get_client_token'
93
+ @params = {
94
+ "oxd_id" => @configuration.oxd_id,
95
+ "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
96
+ "op_host" => @configuration.op_host,
97
+ "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
98
+ "application_type" => @configuration.application_type,
99
+ "response_types"=> @configuration.response_types,
100
+ "grant_types" => @configuration.grant_types,
101
+ "scope" => @configuration.scope,
102
+ "acr_values" => @configuration.acr_values,
103
+ "client_name" => @configuration.client_name,
104
+ "client_jwks_uri" => @configuration.client_jwks_uri,
105
+ "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
106
+ "client_request_uris" => @configuration.client_request_uris,
107
+ "client_sector_identifier_uri" => @configuration.client_sector_identifier_uri,
108
+ "contacts" => @configuration.contacts,
109
+ "ui_locales" => @configuration.ui_locales,
110
+ "claims_locales" => @configuration.claims_locales,
111
+ "client_id" => @configuration.client_id,
112
+ "client_secret" => @configuration.client_secret,
113
+ "client_frontchannel_logout_uris"=> @configuration.client_logout_uris,
114
+ "oxd_rp_programming_language" => 'ruby'
115
+ }
116
+ request('get-client-token')
117
+ @configuration.protection_access_token = getResponseData['access_token']
118
+ end
119
+
120
+ # @param scope [Array] OPTIONAL, scopes required, takes the scopes registered with register_site by defualt
52
121
  # @param acr_values [Array] OPTIONAL, list of acr values in the order of priority
122
+ # @param custom_params [Hash] OPTIONAL, custom parameters
53
123
  # @return [String] authorization_url
54
124
  # 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
56
- def get_authorization_url(acr_values = [""])
57
- @command = 'get_authorization_url'
125
+ # works with oxd-to-https and oxd-server
126
+ def get_authorization_url(scope = [], acr_values = [], custom_params = {})
127
+ logger(:log_msg => "@configuration object params #{@configuration.inspect}", :error => "")
128
+
129
+ @command = 'get_authorization_url'
58
130
  @params = {
59
131
  "oxd_id" => @configuration.oxd_id,
60
132
  "prompt" => @configuration.prompt,
61
- "acr_values" => acr_values || @configuration.acr_values
133
+ "scope" => (scope.blank?)? @configuration.scope : scope,
134
+ "acr_values" => (acr_values.blank?)? @configuration.acr_values : acr_values,
135
+ "custom_parameters" => custom_params,
136
+ "protection_access_token" => @configuration.protection_access_token
62
137
  }
138
+ logger(:log_msg => "get_authorization_url params #{@params.inspect}", :error => "")
63
139
  request('get-authorization-url')
64
140
  getResponseData['authorization_url']
65
141
  end
@@ -68,8 +144,8 @@ module Oxd
68
144
  # @param state [String] state obtained from the authorization url callback
69
145
  # @return [Hash] {:access_token, :id_token}
70
146
  # 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
72
- def get_tokens_by_code( code,state )
147
+ # works with oxd-to-https and oxd-server
148
+ def get_tokens_by_code( code, state )
73
149
  if (code.empty?)
74
150
  logger(:log_msg => "Empty/Wrong value in place of code.")
75
151
  end
@@ -77,17 +153,35 @@ module Oxd
77
153
  @params = {
78
154
  "oxd_id" => @configuration.oxd_id,
79
155
  "code" => code,
80
- "state" => state
156
+ "state" => state,
157
+ "protection_access_token" => @configuration.protection_access_token
81
158
  }
82
159
  request('get-tokens-by-code')
83
160
  @configuration.id_token = getResponseData['id_token']
161
+ @configuration.refresh_token = getResponseData['refresh_token']
162
+ getResponseData['access_token']
163
+ end
164
+
165
+ # @param scope [Array] OPTIONAL, scopes required, takes the scopes registered with register_site by defualt
166
+ # @return [String] access_token
167
+ # method to retrieve access token. It is called after getting the refresh_token by using the code and state.
168
+ # works with oxd-to-https and oxd-server
169
+ def get_access_token_by_refresh_token(scope = nil)
170
+ @command = 'get_access_token_by_refresh_token'
171
+ @params = {
172
+ "oxd_id" => @configuration.oxd_id,
173
+ "refresh_token" => @configuration.refresh_token,
174
+ "scope" => (scope.blank?)? @configuration.scope : scope,
175
+ "protection_access_token" => @configuration.protection_access_token
176
+ }
177
+ request('get-access-token-by-refresh-token')
84
178
  getResponseData['access_token']
85
179
  end
86
180
 
87
181
  # @param access_token [String] access token recieved from the get_tokens_by_code command
88
182
  # @return [String] user data claims that are returned by the OP
89
183
  # get the information about the user using the access token obtained from the OP
90
- # works with both oxd-to-http and oxd-server
184
+ # works with oxd-to-https and oxd-server
91
185
  def get_user_info(access_token)
92
186
  if access_token.empty?
93
187
  logger(:log_msg => "Empty access code sent for get_user_info", :error => "Empty access code")
@@ -95,7 +189,8 @@ module Oxd
95
189
  @command = 'get_user_info'
96
190
  @params = {
97
191
  "oxd_id" => @configuration.oxd_id,
98
- "access_token" => access_token
192
+ "access_token" => access_token,
193
+ "protection_access_token" => @configuration.protection_access_token
99
194
  }
100
195
  request('get-user-info')
101
196
  getResponseData['claims']
@@ -105,7 +200,7 @@ module Oxd
105
200
  # @param session_state [String] OPTIONAL, session state obtained from the authorization url callback
106
201
  # @return [String] uri
107
202
  # 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
203
+ # works with oxd-to-https and oxd-server
109
204
  def get_logout_uri( state = nil, session_state = nil)
110
205
  @command = 'get_logout_uri'
111
206
  @params = {
@@ -113,36 +208,40 @@ module Oxd
113
208
  "id_token_hint" => @configuration.id_token,
114
209
  "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
115
210
  "state" => state,
116
- "session_state" => session_state
211
+ "session_state" => session_state,
212
+ "protection_access_token" => @configuration.protection_access_token
117
213
  }
118
- request('logout')
214
+ request('get-logout-uri')
119
215
  getResponseData['uri']
120
- #@configuration.oxd_id = "" #unset oxd_id after logout
121
216
  end
122
217
 
123
218
  # @return [Boolean] status - if site registration was updated successfully or not
124
219
  # method to update the website's information with OpenID Provider.
125
220
  # This should be called after changing the values in the oxd_config file.
126
- # works with both oxd-to-http and oxd-server
221
+ # works with oxd-to-https and oxd-server
127
222
  def update_site_registration
128
223
  @command = 'update_site_registration'
129
224
  @params = {
130
- "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
131
225
  "oxd_id" => @configuration.oxd_id,
132
- "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
133
- "application_type" => @configuration.application_type,
134
- "acr_values" => @configuration.acr_values,
135
- "scope" => @configuration.scope,
136
- "client_jwks_uri" => @configuration.client_jwks_uri,
137
- "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
138
- "client_request_uris" => @configuration.client_request_uris,
139
- "contacts" => @configuration.contacts,
140
- "grant_types" => @configuration.grant_types,
141
- "response_types"=> @configuration.response_types,
142
- "client_secret_expires_at" => 3080736637943,
143
- "client_logout_uris"=> @configuration.client_logout_uris
226
+ "authorization_redirect_uri" => @configuration.authorization_redirect_uri,
227
+ "post_logout_redirect_uri" => @configuration.post_logout_redirect_uri,
228
+ "client_logout_uris"=> @configuration.client_logout_uris,
229
+ "response_types"=> @configuration.response_types,
230
+ "grant_types" => @configuration.grant_types,
231
+ "scope" => @configuration.scope,
232
+ "acr_values" => @configuration.acr_values,
233
+ "client_name" => @configuration.client_name,
234
+ "client_secret_expires_at" => 3080736637943,
235
+ "client_jwks_uri" => @configuration.client_jwks_uri,
236
+ "client_token_endpoint_auth_method" => @configuration.client_token_endpoint_auth_method,
237
+ "client_request_uris" => @configuration.client_request_uris,
238
+ "client_sector_identifier_uri" => @configuration.client_sector_identifier_uri,
239
+ "contacts" => @configuration.contacts,
240
+ "ui_locales" => @configuration.ui_locales,
241
+ "claims_locales" => @configuration.claims_locales,
242
+ "protection_access_token" => @configuration.protection_access_token
144
243
  }
145
- request('update-site-registration')
244
+ request('update-site')
146
245
  if @response_object['status'] == "ok"
147
246
  @configuration.oxd_id = getResponseData['oxd_id']
148
247
  return true
@@ -150,5 +249,10 @@ module Oxd
150
249
  return false
151
250
  end
152
251
  end
252
+
253
+ # @return Oxd Configuraton object
254
+ def oxdConfig
255
+ return @configuration
256
+ end
153
257
  end
154
258
  end
@@ -1,7 +1,7 @@
1
1
  require 'active_support/configurable'
2
2
 
3
3
  # @author Inderpal Singh
4
- # @note supports oxd-version 2.4.4
4
+ # @note supports oxd-version 3.1.1
5
5
  module Oxd
6
6
 
7
7
  # Configures global settings for Oxd
@@ -26,28 +26,37 @@ module Oxd
26
26
  class Configuration
27
27
  include ActiveSupport::Configurable
28
28
  config_accessor :oxd_host_ip
29
- config_accessor :oxd_host_port
29
+ config_accessor :oxd_host_port
30
30
  config_accessor :op_host
31
31
  config_accessor :client_id
32
32
  config_accessor :client_secret
33
- config_accessor :application_type
34
- config_accessor :prompt
33
+ config_accessor :client_name
35
34
  config_accessor :authorization_redirect_uri
36
- config_accessor :post_logout_redirect_uri
37
- config_accessor :client_logout_uris
38
35
  config_accessor :logout_redirect_uri
36
+ config_accessor :post_logout_redirect_uri
37
+ config_accessor :scope
39
38
  config_accessor :grant_types
39
+ config_accessor :application_type
40
+ config_accessor :response_types
40
41
  config_accessor :acr_values
41
42
  config_accessor :client_jwks_uri
42
43
  config_accessor :client_token_endpoint_auth_method
43
44
  config_accessor :client_request_uris
44
- config_accessor :scope
45
- config_accessor :id_token
46
45
  config_accessor :contacts
47
- config_accessor :response_types
46
+ config_accessor :client_logout_uris
47
+ config_accessor :connection_type
48
+ config_accessor :oxd_host
49
+ config_accessor :dynamic_registration
50
+ config_accessor :prompt
51
+ config_accessor :id_token
52
+ config_accessor :refresh_token
48
53
  config_accessor :oxd_id
49
- config_accessor :rpt
50
54
  config_accessor :ticket
55
+ config_accessor :rpt
56
+ config_accessor :client_sector_identifier_uri
57
+ config_accessor :ui_locales
58
+ config_accessor :claims_locales
59
+ config_accessor :protection_access_token
51
60
 
52
61
  # define param_name writer
53
62
  def param_name
@@ -92,10 +101,18 @@ module Oxd
92
101
  config.client_jwks_uri = ""
93
102
  config.client_token_endpoint_auth_method = ""
94
103
  config.client_request_uris = []
95
- config.scope = ["openid", "profile","uma_protection","uma_authorization"]
104
+ config.scope = ["openid", "profile", "email", "uma_protection","uma_authorization"]
96
105
  config.contacts = ["example-email@gmail.com"]
97
106
  config.response_types = ["code"]
98
107
  config.oxd_id = ""
99
108
  config.id_token = ""
109
+ config.client_name = ""
110
+ config.client_sector_identifier_uri = ""
111
+ config.ui_locales = []
112
+ config.claims_locales = []
113
+ config.protection_access_token = ""
114
+ config.oxd_host = ""
115
+ config.dynamic_registration = true
116
+ config.connection_type = 'local'
100
117
  end
101
118
  end