stormpath-sdk 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/lib/stormpath-sdk.rb +1 -0
- data/lib/stormpath-sdk/data_store.rb +5 -1
- data/lib/stormpath-sdk/oauth/social_grant.rb +4 -2
- data/lib/stormpath-sdk/oauth/social_grant_request.rb +2 -1
- data/lib/stormpath-sdk/provider/account_resolver.rb +3 -1
- data/lib/stormpath-sdk/provider/facebook/facebook_provider.rb +1 -1
- data/lib/stormpath-sdk/provider/google/google_provider.rb +2 -1
- data/lib/stormpath-sdk/provider/provider.rb +6 -3
- data/lib/stormpath-sdk/provider/provider_data.rb +3 -3
- data/lib/stormpath-sdk/resource/application.rb +17 -21
- data/lib/stormpath-sdk/resource/directory.rb +4 -3
- data/lib/stormpath-sdk/resource/instance.rb +3 -5
- data/lib/stormpath-sdk/resource/user_info_mapping_rules.rb +19 -0
- data/lib/stormpath-sdk/version.rb +2 -2
- data/spec/client_spec.rb +5 -6
- data/spec/provider/provider_spec.rb +40 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f08a60486a9c8f8163b91cacc5ed4190d5f3a81
|
4
|
+
data.tar.gz: 7ebc9d89ffc3a00137239866b8cb42be81617ac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f0f63caa6e142c84858aa23f92f24adc2b7d22802c38b4c472ff0e256b5a60c3328960a621b72dfaf1efd1f5fb446bbd64ab83fd825651a94b8b1e31996b96d
|
7
|
+
data.tar.gz: 229efc9202e3a12b95f0a2fa9322801c0948eb5678d300c04f3ec38b94d021649f28665707e822704772c150b19560f16e628780eea939b9be81faea536ffeb3
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
stormpath-sdk-ruby Changelog
|
2
2
|
============================
|
3
3
|
|
4
|
+
Version 1.6.0
|
5
|
+
-------------
|
6
|
+
|
7
|
+
Released on January 26, 2017
|
8
|
+
|
9
|
+
- Implement Social login V2 - user info mapping rules on a directory, custom attributes for Google(hd, display, access_type), provider scope, redirect_uri on social grant requests
|
10
|
+
|
11
|
+
|
4
12
|
Version 1.5.0
|
5
13
|
-------------
|
6
14
|
|
data/lib/stormpath-sdk.rb
CHANGED
@@ -67,6 +67,7 @@ module Stormpath
|
|
67
67
|
autoload :Challenge, 'stormpath-sdk/resource/challenge'
|
68
68
|
autoload :Schema, 'stormpath-sdk/resource/schema'
|
69
69
|
autoload :Field, 'stormpath-sdk/resource/field'
|
70
|
+
autoload :UserInfoMappingRules, 'stormpath-sdk/resource/user_info_mapping_rules'
|
70
71
|
end
|
71
72
|
|
72
73
|
module Cache
|
@@ -158,7 +158,7 @@ class Stormpath::DataStore
|
|
158
158
|
|
159
159
|
return if http_method == 'delete'
|
160
160
|
|
161
|
-
if result[HREF_PROP_NAME]
|
161
|
+
if result[HREF_PROP_NAME] && !resource_is_saml_mapping_rules?(resource) && !user_info_mapping_rules?(resource)
|
162
162
|
cache_walk result
|
163
163
|
else
|
164
164
|
result
|
@@ -348,6 +348,10 @@ class Stormpath::DataStore
|
|
348
348
|
Stormpath::Resource::ApplicationWebConfig::ENDPOINTS.include?(name.underscore.to_sym)
|
349
349
|
end
|
350
350
|
|
351
|
+
def user_info_mapping_rules?(resource)
|
352
|
+
resource.is_a?(Stormpath::Resource::UserInfoMappingRules)
|
353
|
+
end
|
354
|
+
|
351
355
|
def resource_is_saml_mapping_rules?(resource)
|
352
356
|
resource.is_a?(Stormpath::Provider::SamlMappingRules)
|
353
357
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
module Stormpath
|
2
2
|
module Oauth
|
3
3
|
class SocialGrant < Stormpath::Resource::Base
|
4
|
-
prop_accessor :grant_type, :provider_id, :code, :access_token
|
4
|
+
prop_accessor :grant_type, :provider_id, :code, :access_token, :redirect_uri
|
5
5
|
|
6
6
|
def form_properties
|
7
7
|
{
|
8
8
|
grant_type: grant_type,
|
9
9
|
providerId: provider_id,
|
10
10
|
code: code,
|
11
|
-
accessToken: access_token
|
11
|
+
accessToken: access_token,
|
12
|
+
redirectUri: redirect_uri
|
12
13
|
}
|
13
14
|
end
|
14
15
|
|
@@ -16,6 +17,7 @@ module Stormpath
|
|
16
17
|
set_property :provider_id, request.provider_id
|
17
18
|
set_property :code, request.code if request.code
|
18
19
|
set_property :access_token, request.access_token if request.access_token
|
20
|
+
set_property :redirect_uri, request.redirect_uri if request.redirect_uri
|
19
21
|
set_property :grant_type, request.grant_type
|
20
22
|
end
|
21
23
|
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module Stormpath
|
2
2
|
module Oauth
|
3
3
|
class SocialGrantRequest
|
4
|
-
attr_accessor :grant_type, :provider_id, :code, :access_token
|
4
|
+
attr_accessor :grant_type, :provider_id, :code, :access_token, :redirect_uri
|
5
5
|
|
6
6
|
def initialize(provider_id, options = {})
|
7
7
|
@provider_id = provider_id.to_s
|
8
8
|
@code = options[:code]
|
9
9
|
@access_token = options[:access_token]
|
10
|
+
@redirect_uri = options[:redirect_uri]
|
10
11
|
@grant_type = 'stormpath_social'
|
11
12
|
end
|
12
13
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2016 Stormpath, Inc.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -33,6 +33,8 @@ module Stormpath
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def provider_data
|
36
|
+
# TODO: need to add an options hash and pass all attributes from the providers?
|
37
|
+
# https://stormpath.atlassian.net/wiki/display/AM/Social+Login+V2/#SocialLoginV2-ClientAPIChanges
|
36
38
|
@provider_data ||= {}.tap do |body|
|
37
39
|
body[request.token_type.to_s.camelize(:lower)] = request.token_value
|
38
40
|
body['providerId'] = request.provider
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2016 Stormpath, Inc.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -13,6 +13,9 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
|
-
class Stormpath::Provider::Provider < Stormpath::Resource::
|
16
|
+
class Stormpath::Provider::Provider < Stormpath::Resource::Instance
|
17
|
+
prop_accessor :scope
|
17
18
|
prop_reader :provider_id, :created_at, :modified_at
|
18
|
-
|
19
|
+
|
20
|
+
has_one :user_info_mapping_rules
|
21
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2016 Stormpath, Inc.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -14,5 +14,5 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
class Stormpath::Provider::ProviderData < Stormpath::Resource::Base
|
17
|
-
prop_reader :provider_id, :created_at, :modified_at
|
18
|
-
end
|
17
|
+
prop_reader :provider_id, :created_at, :modified_at, :user_info
|
18
|
+
end
|
@@ -59,19 +59,17 @@ class Stormpath::Resource::Application < Stormpath::Resource::Instance
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def create_id_site_url(options = {})
|
62
|
-
base = client.data_store.base_url.sub("v
|
62
|
+
base = client.data_store.base_url.sub("v#{Stormpath::DataStore::DEFAULT_API_VERSION}", 'sso')
|
63
63
|
base += '/logout' if options[:logout]
|
64
64
|
|
65
|
-
if options[:callback_uri].empty?
|
66
|
-
raise Stormpath::Oauth::Error.new(:jwt_cb_uri_incorrect)
|
67
|
-
end
|
65
|
+
raise Stormpath::Oauth::Error.new(:jwt_cb_uri_incorrect) if options[:callback_uri].empty?
|
68
66
|
|
69
67
|
token = JWT.encode(jwt_token_payload(options), client.data_store.api_key.secret, 'HS256')
|
70
68
|
base + '?jwtRequest=' + token
|
71
69
|
end
|
72
70
|
|
73
71
|
def handle_id_site_callback(response_url)
|
74
|
-
assert_not_nil response_url,
|
72
|
+
assert_not_nil response_url, 'No response provided. Please provide response object.'
|
75
73
|
|
76
74
|
uri = URI(response_url)
|
77
75
|
params = CGI::parse(uri.query)
|
@@ -99,11 +97,11 @@ class Stormpath::Resource::Application < Stormpath::Resource::Instance
|
|
99
97
|
password_reset_token.account
|
100
98
|
end
|
101
99
|
|
102
|
-
def verify_password_reset_token
|
100
|
+
def verify_password_reset_token(token)
|
103
101
|
password_reset_tokens.get(token).account
|
104
102
|
end
|
105
103
|
|
106
|
-
def authenticate_account
|
104
|
+
def authenticate_account(request)
|
107
105
|
Stormpath::Authentication::BasicAuthenticator.new(data_store).authenticate(href, request)
|
108
106
|
end
|
109
107
|
|
@@ -118,20 +116,18 @@ class Stormpath::Resource::Application < Stormpath::Resource::Instance
|
|
118
116
|
private
|
119
117
|
|
120
118
|
def jwt_token_payload(options)
|
121
|
-
|
122
|
-
'iat'
|
123
|
-
'jti'
|
124
|
-
'iss'
|
125
|
-
'sub'
|
126
|
-
'cb_uri'
|
127
|
-
'path'
|
128
|
-
'state'
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
payload["usd"] = options[:use_subdomain] if options[:use_subdomain]
|
134
|
-
payload
|
119
|
+
{}.tap do |payload|
|
120
|
+
payload['iat'] = Time.now.to_i
|
121
|
+
payload['jti'] = UUID.method(:random_create).call.to_s
|
122
|
+
payload['iss'] = client.data_store.api_key.id
|
123
|
+
payload['sub'] = href
|
124
|
+
payload['cb_uri'] = options[:callback_uri]
|
125
|
+
payload['path'] = options[:path] || ''
|
126
|
+
payload['state'] = options[:state] || ''
|
127
|
+
payload['sof'] = options[:show_organization_field]
|
128
|
+
payload['onk'] = options[:organization_name_key]
|
129
|
+
payload['usd'] = options[:use_subdomain]
|
130
|
+
end.compact
|
135
131
|
end
|
136
132
|
|
137
133
|
def api_key_id
|
@@ -29,6 +29,7 @@ class Stormpath::Resource::Directory < Stormpath::Resource::Instance
|
|
29
29
|
has_one :password_policy
|
30
30
|
has_one :account_creation_policy
|
31
31
|
has_one :account_schema, class_name: :schema
|
32
|
+
delegate :user_info_mapping_rules, to: :provider
|
32
33
|
|
33
34
|
def provider
|
34
35
|
internal_instance = instance_variable_get "@_provider"
|
@@ -46,17 +47,17 @@ class Stormpath::Resource::Directory < Stormpath::Resource::Instance
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def provider_metadata
|
49
|
-
metadata_href = provider.service_provider_metadata[
|
50
|
+
metadata_href = provider.service_provider_metadata['href']
|
50
51
|
data_store.get_resource metadata_href, Stormpath::Provider::SamlProviderMetadata
|
51
52
|
end
|
52
53
|
|
53
54
|
def statement_mapping_rules
|
54
|
-
metadata_href = provider.attribute_statement_mapping_rules[
|
55
|
+
metadata_href = provider.attribute_statement_mapping_rules['href']
|
55
56
|
data_store.get_resource metadata_href, Stormpath::Provider::SamlMappingRules
|
56
57
|
end
|
57
58
|
|
58
59
|
def create_attribute_mappings(mappings)
|
59
|
-
mappings.set_options(href: provider.attribute_statement_mapping_rules[
|
60
|
+
mappings.set_options(href: provider.attribute_statement_mapping_rules['href'])
|
60
61
|
data_store.create mappings.href, mappings, Stormpath::Provider::SamlMappingRules
|
61
62
|
end
|
62
63
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright
|
2
|
+
# Copyright 2016 Stormpath, Inc.
|
3
3
|
#
|
4
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
5
|
# you may not use this file except in compliance with the License.
|
@@ -15,12 +15,10 @@
|
|
15
15
|
#
|
16
16
|
class Stormpath::Resource::Instance < Stormpath::Resource::Base
|
17
17
|
def save
|
18
|
-
data_store.save
|
18
|
+
data_store.save(self)
|
19
19
|
end
|
20
20
|
|
21
21
|
def delete
|
22
|
-
unless new?
|
23
|
-
data_store.delete self
|
24
|
-
end
|
22
|
+
data_store.delete(self) unless new?
|
25
23
|
end
|
26
24
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2016 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::Resource::UserInfoMappingRules < Stormpath::Resource::Instance
|
17
|
+
prop_accessor :items
|
18
|
+
prop_reader :href, :created_at, :modified_at
|
19
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -290,7 +290,7 @@ properties
|
|
290
290
|
context 'pagination' do
|
291
291
|
let!(:applications) do
|
292
292
|
(0..2).to_a.map do |index|
|
293
|
-
test_api_client.applications.create(application_attrs(name: "ruby-sdk-test-#{index}"))
|
293
|
+
test_api_client.applications.create(application_attrs(name: "ruby-sdk-test-#{index}-#{random_number}"))
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
@@ -537,14 +537,13 @@ properties
|
|
537
537
|
|
538
538
|
describe '#organization' do
|
539
539
|
context 'search' do
|
540
|
+
let(:random_org_name) { "ruby-org-#{random_number}" }
|
540
541
|
let!(:organization) do
|
541
|
-
test_api_client.organizations.create(organization_attrs(name:
|
542
|
+
test_api_client.organizations.create(organization_attrs(name: random_org_name))
|
542
543
|
end
|
543
544
|
|
544
545
|
context 'by any attribute' do
|
545
|
-
let(:search_results)
|
546
|
-
test_api_client.organizations.search('ruby-org')
|
547
|
-
end
|
546
|
+
let(:search_results) { test_api_client.organizations.search(random_org_name) }
|
548
547
|
|
549
548
|
it 'returns the application' do
|
550
549
|
expect(search_results.count).to eq 1
|
@@ -552,7 +551,7 @@ properties
|
|
552
551
|
end
|
553
552
|
|
554
553
|
context 'by an explicit attribute' do
|
555
|
-
let(:search_results) { test_api_client.organizations.search(name:
|
554
|
+
let(:search_results) { test_api_client.organizations.search(name: random_org_name) }
|
556
555
|
|
557
556
|
it 'returns the application' do
|
558
557
|
expect(search_results.count).to eq 1
|
@@ -17,6 +17,10 @@ describe Stormpath::Provider::Provider, :vcr do
|
|
17
17
|
directory.provider
|
18
18
|
end
|
19
19
|
|
20
|
+
def social_directory?
|
21
|
+
provider_id != 'stormpath'
|
22
|
+
end
|
23
|
+
|
20
24
|
after do
|
21
25
|
directory.delete
|
22
26
|
application.delete
|
@@ -41,13 +45,41 @@ describe Stormpath::Provider::Provider, :vcr do
|
|
41
45
|
provider_clazz = "Stormpath::Provider::#{provider_id.capitalize}Provider".constantize
|
42
46
|
expect(provider).to be_instance_of(provider_clazz)
|
43
47
|
|
44
|
-
if
|
48
|
+
if social_directory?
|
45
49
|
expect(provider.client_id).to eq(client_id)
|
46
50
|
expect(provider.client_secret).to eq(client_secret)
|
47
51
|
end
|
48
52
|
|
49
53
|
if provider_id == 'google'
|
50
54
|
expect(provider.redirect_uri).to eq(redirect_uri)
|
55
|
+
expect(provider.hd).to eq(hd)
|
56
|
+
expect(provider.display).to eq(display)
|
57
|
+
expect(provider.access_type).to eq(access_type)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should be able to update the scope' do
|
62
|
+
if social_directory?
|
63
|
+
provider.scope = ['email']
|
64
|
+
provider.save
|
65
|
+
expect(provider.scope).to include 'email'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'user info mapping rules for social directories' do
|
70
|
+
let(:rule) { { 'name' => 'email', 'accountAttributes' => ['email'] } }
|
71
|
+
before do
|
72
|
+
if social_directory?
|
73
|
+
directory.user_info_mapping_rules.items = [rule]
|
74
|
+
directory.user_info_mapping_rules.save
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should be able to create and fetch user info mapping rules' do
|
79
|
+
if social_directory?
|
80
|
+
expect(directory.user_info_mapping_rules).to be_kind_of(Stormpath::Resource::UserInfoMappingRules)
|
81
|
+
expect(directory.user_info_mapping_rules.items).to include(rule)
|
82
|
+
end
|
51
83
|
end
|
52
84
|
end
|
53
85
|
end
|
@@ -129,12 +161,18 @@ describe Stormpath::Provider::Provider, :vcr do
|
|
129
161
|
let(:client_id) { 'GOOGLE_CLIENT_ID' }
|
130
162
|
let(:client_secret) { 'GOOGLE_CLIENT_SECRET' }
|
131
163
|
let(:redirect_uri) { 'GOOGLE_REDIRECT_URI' }
|
164
|
+
let(:hd) { 'www.example.com' }
|
165
|
+
let(:display) { 'page' }
|
166
|
+
let(:access_type) { 'online' }
|
132
167
|
let(:provider_info) do
|
133
168
|
{
|
134
169
|
provider_id: provider_id,
|
135
170
|
client_id: client_id,
|
136
171
|
client_secret: client_secret,
|
137
|
-
redirect_uri: redirect_uri
|
172
|
+
redirect_uri: redirect_uri,
|
173
|
+
hd: hd,
|
174
|
+
display: display,
|
175
|
+
access_type: access_type
|
138
176
|
}
|
139
177
|
end
|
140
178
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stormpath-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stormpath, Inc
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-01-
|
12
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -428,6 +428,7 @@ files:
|
|
428
428
|
- lib/stormpath-sdk/resource/refresh_token.rb
|
429
429
|
- lib/stormpath-sdk/resource/schema.rb
|
430
430
|
- lib/stormpath-sdk/resource/tenant.rb
|
431
|
+
- lib/stormpath-sdk/resource/user_info_mapping_rules.rb
|
431
432
|
- lib/stormpath-sdk/resource/utils.rb
|
432
433
|
- lib/stormpath-sdk/resource/verification_email.rb
|
433
434
|
- lib/stormpath-sdk/util/assert.rb
|