stormpath-sdk 1.0.0.beta.6 → 1.0.0.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/CHANGES.md +10 -0
- data/lib/stormpath-sdk.rb +15 -0
- data/lib/stormpath-sdk/data_store.rb +30 -14
- data/lib/stormpath-sdk/http/request.rb +5 -25
- data/lib/stormpath-sdk/http/response.rb +0 -5
- data/lib/stormpath-sdk/provider/account_access.rb +28 -0
- data/lib/stormpath-sdk/provider/account_request.rb +30 -0
- data/lib/stormpath-sdk/provider/account_resolver.rb +43 -0
- data/lib/stormpath-sdk/provider/account_result.rb +27 -0
- data/lib/stormpath-sdk/provider/facebook/facebook_provider.rb +18 -0
- data/lib/stormpath-sdk/provider/facebook/facebook_provider_data.rb +18 -0
- data/lib/stormpath-sdk/provider/google/google_provider.rb +18 -0
- data/lib/stormpath-sdk/provider/google/google_provider_data.rb +19 -0
- data/lib/stormpath-sdk/provider/provider.rb +18 -0
- data/lib/stormpath-sdk/provider/provider_data.rb +18 -0
- data/lib/stormpath-sdk/provider/stormpath/stormpath_provider.rb +17 -0
- data/lib/stormpath-sdk/provider/stormpath/stormpath_provider_data.rb +17 -0
- data/lib/stormpath-sdk/resource/account.rb +15 -0
- data/lib/stormpath-sdk/resource/application.rb +5 -2
- data/lib/stormpath-sdk/resource/associations.rb +7 -5
- data/lib/stormpath-sdk/resource/directory.rb +15 -0
- data/lib/stormpath-sdk/version.rb +2 -2
- data/spec/auth/basic_authenticator_spec.rb +5 -5
- data/spec/cache/cache_entry_spec.rb +3 -3
- data/spec/client_spec.rb +27 -20
- data/spec/provider/account_resolver_spec.rb +25 -0
- data/spec/provider/provider_spec.rb +152 -0
- data/spec/resource/account_spec.rb +26 -30
- data/spec/resource/account_store_mapping_spec.rb +28 -27
- data/spec/resource/account_store_spec.rb +7 -7
- data/spec/resource/application_spec.rb +34 -26
- data/spec/resource/collection_spec.rb +34 -34
- data/spec/resource/custom_data_spec.rb +2 -2
- data/spec/resource/directory_spec.rb +25 -23
- data/spec/resource/group_membership_spec.rb +3 -3
- data/spec/resource/group_spec.rb +16 -17
- data/spec/resource/status_spec.rb +16 -16
- data/spec/resource/tenant_spec.rb +10 -8
- data/spec/spec_helper.rb +37 -18
- data/spec/support/custom_data_storage_behavior.rb +19 -19
- data/spec/support/mocked_provider_accounts.rb +72 -0
- data/stormpath-sdk.gemspec +5 -9
- metadata +104 -111
- checksums.yaml +0 -7
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
stormpath-sdk-ruby Changelog
|
2
2
|
============================
|
3
3
|
|
4
|
+
Version 1.0.0.beta.7
|
5
|
+
--------------------
|
6
|
+
|
7
|
+
Released on July 21, 2014
|
8
|
+
|
9
|
+
- Added provider integration (Google, Facebook and Stormpath).
|
10
|
+
- Updated tests to use RSpec3.
|
11
|
+
- Updated tests to run in parallel in multiple versions (1.9.3, 2.0.0 and 2.1.2).
|
12
|
+
|
13
|
+
|
4
14
|
Version 1.0.0.beta.6
|
5
15
|
--------------------
|
6
16
|
|
data/lib/stormpath-sdk.rb
CHANGED
@@ -66,6 +66,21 @@ module Stormpath
|
|
66
66
|
autoload :BasicAuthenticator, "stormpath-sdk/auth/basic_authenticator"
|
67
67
|
end
|
68
68
|
|
69
|
+
module Provider
|
70
|
+
autoload :AccountResolver, "stormpath-sdk/provider/account_resolver"
|
71
|
+
autoload :AccountAccess, "stormpath-sdk/provider/account_access"
|
72
|
+
autoload :AccountResult, "stormpath-sdk/provider/account_result"
|
73
|
+
autoload :AccountRequest, "stormpath-sdk/provider/account_request"
|
74
|
+
autoload :Provider, 'stormpath-sdk/provider/provider'
|
75
|
+
autoload :ProviderData, 'stormpath-sdk/provider/provider_data'
|
76
|
+
autoload :FacebookProvider, 'stormpath-sdk/provider/facebook/facebook_provider'
|
77
|
+
autoload :FacebookProviderData, 'stormpath-sdk/provider/facebook/facebook_provider_data'
|
78
|
+
autoload :GoogleProvider, 'stormpath-sdk/provider/google/google_provider'
|
79
|
+
autoload :GoogleProviderData, 'stormpath-sdk/provider/google/google_provider_data'
|
80
|
+
autoload :StormpathProvider, 'stormpath-sdk/provider/stormpath/stormpath_provider'
|
81
|
+
autoload :StormpathProviderData, 'stormpath-sdk/provider/stormpath/stormpath_provider_data'
|
82
|
+
end
|
83
|
+
|
69
84
|
module Http
|
70
85
|
autoload :Utils, "stormpath-sdk/http/utils"
|
71
86
|
autoload :Request, "stormpath-sdk/http/request"
|
@@ -22,7 +22,7 @@ class Stormpath::DataStore
|
|
22
22
|
DEFAULT_BASE_URL = "https://" + DEFAULT_SERVER_HOST + "/v" + DEFAULT_API_VERSION.to_s
|
23
23
|
HREF_PROP_NAME = Stormpath::Resource::Base::HREF_PROP_NAME
|
24
24
|
|
25
|
-
CACHE_REGIONS = %w(
|
25
|
+
CACHE_REGIONS = %w(applications directories accounts groups groupMemberships accountMemberships tenants customData provider providerData)
|
26
26
|
|
27
27
|
attr_reader :client, :request_executor, :cache_manager
|
28
28
|
|
@@ -53,6 +53,9 @@ class Stormpath::DataStore
|
|
53
53
|
q_href = qualify href
|
54
54
|
|
55
55
|
data = execute_request('get', q_href, nil, query)
|
56
|
+
|
57
|
+
clazz = clazz.call(data) if clazz.respond_to? :call
|
58
|
+
|
56
59
|
instantiate clazz, data.to_hash
|
57
60
|
end
|
58
61
|
|
@@ -89,29 +92,36 @@ class Stormpath::DataStore
|
|
89
92
|
href = resource.href
|
90
93
|
href += "/#{property_name}" if property_name
|
91
94
|
href = qualify(href)
|
92
|
-
|
95
|
+
|
93
96
|
execute_request('delete', href)
|
97
|
+
clear_cache_on_delete(href)
|
98
|
+
return nil
|
94
99
|
end
|
95
100
|
|
96
101
|
private
|
97
102
|
|
98
|
-
def needs_to_be_fully_qualified(href)
|
103
|
+
def needs_to_be_fully_qualified?(href)
|
99
104
|
!href.downcase.start_with? 'http'
|
100
105
|
end
|
101
106
|
|
102
107
|
def qualify(href)
|
103
|
-
needs_to_be_fully_qualified(href) ? @base_url + href : href
|
108
|
+
needs_to_be_fully_qualified?(href) ? @base_url + href : href
|
104
109
|
end
|
105
110
|
|
106
|
-
def execute_request(http_method, href,
|
111
|
+
def execute_request(http_method, href, resource=nil, query=nil)
|
107
112
|
if http_method == 'get' && (cache = cache_for href)
|
108
113
|
cached_result = cache.get href
|
109
114
|
return cached_result if cached_result
|
110
115
|
end
|
111
116
|
|
117
|
+
body = if resource
|
118
|
+
MultiJson.dump(to_hash(resource))
|
119
|
+
end
|
120
|
+
|
112
121
|
request = Request.new(http_method, href, query, Hash.new, body)
|
113
122
|
apply_default_request_headers request
|
114
123
|
response = @request_executor.execute_request request
|
124
|
+
|
115
125
|
result = response.body.length > 0 ? MultiJson.load(response.body) : ''
|
116
126
|
|
117
127
|
if response.error?
|
@@ -119,11 +129,13 @@ class Stormpath::DataStore
|
|
119
129
|
raise Stormpath::Error.new error
|
120
130
|
end
|
121
131
|
|
122
|
-
if
|
123
|
-
|
124
|
-
|
132
|
+
if resource.is_a? Stormpath::Provider::AccountAccess
|
133
|
+
is_new_account = response.http_status == 201
|
134
|
+
result = {is_new_account: is_new_account, account: result }
|
125
135
|
end
|
126
136
|
|
137
|
+
return if http_method == 'delete'
|
138
|
+
|
127
139
|
if result[HREF_PROP_NAME]
|
128
140
|
cache_walk result
|
129
141
|
else
|
@@ -206,7 +218,7 @@ class Stormpath::DataStore
|
|
206
218
|
|
207
219
|
clear_cache_on_save(resource)
|
208
220
|
|
209
|
-
response = execute_request 'post', q_href,
|
221
|
+
response = execute_request 'post', q_href, resource
|
210
222
|
|
211
223
|
instantiate return_type, response.to_hash
|
212
224
|
end
|
@@ -242,11 +254,11 @@ class Stormpath::DataStore
|
|
242
254
|
def to_hash(resource)
|
243
255
|
Hash.new.tap do |properties|
|
244
256
|
resource.get_dirty_property_names.each do |name|
|
245
|
-
ignore_camelcasing =
|
257
|
+
ignore_camelcasing = resource_is_custom_data(resource, name)
|
246
258
|
property = resource.get_property name, ignore_camelcasing: ignore_camelcasing
|
247
259
|
|
248
|
-
# Special use
|
249
|
-
if property.kind_of?(Hash) and
|
260
|
+
# Special use cases are with Custom Data, Provider and ProviderData, their hashes should not be simplified
|
261
|
+
if property.kind_of?(Hash) and !resource_nested_submittable(resource, name)
|
250
262
|
property = to_simple_reference name, property
|
251
263
|
end
|
252
264
|
|
@@ -263,8 +275,12 @@ class Stormpath::DataStore
|
|
263
275
|
{HREF_PROP_NAME => href}
|
264
276
|
end
|
265
277
|
|
266
|
-
def
|
267
|
-
|
278
|
+
def resource_nested_submittable resource, name
|
279
|
+
['provider', 'providerData'].include?(name) or resource_is_custom_data(resource, name)
|
280
|
+
end
|
281
|
+
|
282
|
+
def resource_is_custom_data resource, name
|
283
|
+
resource.is_a? Stormpath::Resource::CustomData or name == 'customData'
|
268
284
|
end
|
269
285
|
|
270
286
|
end
|
@@ -24,37 +24,25 @@ module Stormpath
|
|
24
24
|
|
25
25
|
splitted = href.split '?'
|
26
26
|
|
27
|
-
|
28
|
-
@query_string = Hash.new
|
29
|
-
else
|
30
|
-
@query_string = query_string
|
31
|
-
end
|
27
|
+
@query_string = query_string || {}
|
32
28
|
|
33
|
-
if
|
29
|
+
if splitted and splitted.length > 1
|
34
30
|
@href = splitted[0]
|
35
31
|
query_string_str = splitted[1]
|
36
|
-
|
37
32
|
query_string_arr = query_string_str.split '&'
|
38
|
-
|
39
33
|
query_string_arr.each do |pair|
|
40
|
-
|
41
34
|
pair_arr = pair.split '='
|
42
|
-
|
43
35
|
@query_string.store pair_arr[0], pair_arr[1]
|
44
|
-
|
45
36
|
end
|
46
|
-
|
47
37
|
else
|
48
|
-
|
49
38
|
@href = href
|
50
|
-
|
51
39
|
end
|
52
40
|
|
53
41
|
@http_method = http_method.upcase
|
54
42
|
@http_headers = http_headers
|
55
43
|
@body = body
|
56
44
|
|
57
|
-
if
|
45
|
+
if body
|
58
46
|
@http_headers.store 'Content-Length', @body.bytesize
|
59
47
|
end
|
60
48
|
|
@@ -65,30 +53,22 @@ module Stormpath
|
|
65
53
|
end
|
66
54
|
|
67
55
|
def to_s_query_string canonical
|
68
|
-
|
69
56
|
result = ''
|
70
57
|
|
71
|
-
|
58
|
+
unless @query_string.empty?
|
72
59
|
Hash[@query_string.sort].each do |key, value|
|
73
60
|
|
74
61
|
enc_key = encode_url key, false, canonical
|
75
62
|
enc_value = encode_url value, false, canonical
|
76
63
|
|
77
|
-
|
78
|
-
result << '&'
|
79
|
-
end
|
80
|
-
|
64
|
+
result << '&' unless result.empty?
|
81
65
|
result << enc_key << '='<< enc_value
|
82
|
-
|
83
66
|
end
|
84
|
-
|
85
67
|
end
|
86
68
|
|
87
69
|
result
|
88
70
|
end
|
89
71
|
|
90
72
|
end
|
91
|
-
|
92
73
|
end
|
93
|
-
|
94
74
|
end
|
@@ -14,9 +14,7 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
module Stormpath
|
17
|
-
|
18
17
|
module Http
|
19
|
-
|
20
18
|
class Response
|
21
19
|
|
22
20
|
attr_reader :http_status, :headers, :body
|
@@ -30,7 +28,6 @@ module Stormpath
|
|
30
28
|
@headers.body_size = content_length
|
31
29
|
end
|
32
30
|
|
33
|
-
|
34
31
|
def client_error?
|
35
32
|
http_status >= 400 and http_status < 500
|
36
33
|
end
|
@@ -44,7 +41,5 @@ module Stormpath
|
|
44
41
|
end
|
45
42
|
|
46
43
|
end
|
47
|
-
|
48
44
|
end
|
49
|
-
|
50
45
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Stormpath
|
17
|
+
module Provider
|
18
|
+
class AccountAccess < Stormpath::Resource::Base
|
19
|
+
|
20
|
+
PROVIDER_DATA = :provider_data
|
21
|
+
|
22
|
+
def provider_data=(provider_data)
|
23
|
+
set_property PROVIDER_DATA, provider_data
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Stormpath
|
17
|
+
module Provider
|
18
|
+
class AccountRequest
|
19
|
+
|
20
|
+
attr_accessor :provider, :token_type, :token_value
|
21
|
+
|
22
|
+
def initialize(provider, token_type, token_value)
|
23
|
+
@provider = provider
|
24
|
+
@token_type = token_type
|
25
|
+
@token_value = token_value
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Stormpath
|
17
|
+
module Provider
|
18
|
+
class AccountResolver
|
19
|
+
include Stormpath::Util::Assert
|
20
|
+
|
21
|
+
def initialize data_store
|
22
|
+
@data_store = data_store
|
23
|
+
end
|
24
|
+
|
25
|
+
def resolve_provider_account parent_href, request
|
26
|
+
assert_not_nil parent_href, "parent_href argument must be specified"
|
27
|
+
assert_kind_of AccountRequest, request, "Only #{AccountRequest} instances are supported."
|
28
|
+
|
29
|
+
attempt = @data_store.instantiate AccountAccess
|
30
|
+
|
31
|
+
attempt.provider_data = {
|
32
|
+
request.token_type.to_s.camelize(:lower) => request.token_value,
|
33
|
+
"providerId" => request.provider
|
34
|
+
}
|
35
|
+
|
36
|
+
href = parent_href + '/accounts'
|
37
|
+
|
38
|
+
@data_store.create href, attempt, Stormpath::Provider::AccountResult
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
module Stormpath
|
17
|
+
module Provider
|
18
|
+
class AccountResult < Stormpath::Resource::Base
|
19
|
+
|
20
|
+
prop_reader :is_new_account
|
21
|
+
|
22
|
+
alias_method :is_new_account?, :is_new_account
|
23
|
+
|
24
|
+
has_one :account
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
class Stormpath::Provider::FacebookProvider < Stormpath::Provider::Provider
|
17
|
+
prop_reader :client_id, :client_secret
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
class Stormpath::Provider::FacebookProviderData < Stormpath::Provider::ProviderData
|
17
|
+
prop_reader :access_token
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Stormpath, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
class Stormpath::Provider::GoogleProvider < Stormpath::Provider::Provider
|
17
|
+
prop_reader :client_id, :client_secret, :redirect_uri
|
18
|
+
end
|