stormpath-sdk 1.1.5 → 1.2.0
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/.gitignore +0 -0
- data/.ruby-gemset +0 -0
- data/.travis.yml +1 -0
- data/CHANGES.md +20 -0
- data/Gemfile +0 -0
- data/README.md +78 -2
- data/Rakefile +0 -0
- data/lib/stormpath-sdk/api_key.rb +0 -0
- data/lib/stormpath-sdk/auth/authentication_result.rb +0 -0
- data/lib/stormpath-sdk/auth/basic_authenticator.rb +0 -0
- data/lib/stormpath-sdk/auth/basic_login_attempt.rb +0 -0
- data/lib/stormpath-sdk/auth/http_basic_authentication.rb +47 -0
- data/lib/stormpath-sdk/auth/http_bearer_authentication.rb +27 -0
- data/lib/stormpath-sdk/auth/username_password_request.rb +0 -0
- data/lib/stormpath-sdk/cache/cache.rb +0 -0
- data/lib/stormpath-sdk/cache/cache_entry.rb +0 -0
- data/lib/stormpath-sdk/cache/cache_manager.rb +0 -0
- data/lib/stormpath-sdk/cache/cache_stats.rb +0 -0
- data/lib/stormpath-sdk/cache/disabled_cache_store.rb +0 -0
- data/lib/stormpath-sdk/cache/memcached_store.rb +37 -0
- data/lib/stormpath-sdk/cache/memory_store.rb +0 -0
- data/lib/stormpath-sdk/cache/redis_store.rb +0 -0
- data/lib/stormpath-sdk/client.rb +0 -0
- data/lib/stormpath-sdk/data_store.rb +1 -0
- data/lib/stormpath-sdk/error.rb +5 -5
- data/lib/stormpath-sdk/http/authc/sauthc1_signer.rb +0 -0
- data/lib/stormpath-sdk/http/http_client_request_executor.rb +2 -3
- data/lib/stormpath-sdk/http/request.rb +12 -10
- data/lib/stormpath-sdk/http/response.rb +0 -0
- data/lib/stormpath-sdk/http/utils.rb +8 -5
- data/lib/stormpath-sdk/id_site/id_site_result.rb +0 -0
- data/lib/stormpath-sdk/oauth/access_token_authentication_result.rb +0 -0
- data/lib/stormpath-sdk/oauth/authenticator.rb +2 -1
- data/lib/stormpath-sdk/oauth/error.rb +12 -8
- data/lib/stormpath-sdk/oauth/id_site_grant_request.rb +0 -0
- data/lib/stormpath-sdk/oauth/local_access_token_verification.rb +45 -0
- data/lib/stormpath-sdk/oauth/password_grant.rb +9 -7
- data/lib/stormpath-sdk/oauth/password_grant_request.rb +3 -2
- data/lib/stormpath-sdk/oauth/refresh_grant_request.rb +0 -0
- data/lib/stormpath-sdk/oauth/remote_access_token_verification.rb +28 -0
- data/lib/stormpath-sdk/oauth/social_grant.rb +27 -0
- data/lib/stormpath-sdk/oauth/social_grant_request.rb +14 -0
- data/lib/stormpath-sdk/oauth/stormpath_grant_request.rb +3 -2
- data/lib/stormpath-sdk/oauth/verify_access_token.rb +11 -6
- data/lib/stormpath-sdk/oauth/{verify_token.rb → verify_token_result.rb} +1 -1
- data/lib/stormpath-sdk/provider/account_access.rb +0 -0
- data/lib/stormpath-sdk/provider/account_request.rb +0 -0
- data/lib/stormpath-sdk/provider/account_resolver.rb +0 -0
- data/lib/stormpath-sdk/provider/account_result.rb +0 -0
- data/lib/stormpath-sdk/provider/facebook/facebook_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/facebook/facebook_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/github/github_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/github/github_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/google/google_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/google/google_provider_data.rb +0 -1
- data/lib/stormpath-sdk/provider/linkedin/linkedin_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/linkedin/linkedin_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/provider.rb +0 -0
- data/lib/stormpath-sdk/provider/provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_mapping_rules.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_provider_data.rb +0 -0
- data/lib/stormpath-sdk/provider/saml/saml_provider_metadata.rb +0 -0
- data/lib/stormpath-sdk/provider/stormpath/stormpath_provider.rb +0 -0
- data/lib/stormpath-sdk/provider/stormpath/stormpath_provider_data.rb +0 -0
- data/lib/stormpath-sdk/resource/access_token.rb +0 -0
- data/lib/stormpath-sdk/resource/account_creation_policy.rb +3 -1
- data/lib/stormpath-sdk/resource/account_membership.rb +0 -0
- data/lib/stormpath-sdk/resource/account_overrides.rb +0 -0
- data/lib/stormpath-sdk/resource/account_store.rb +7 -8
- data/lib/stormpath-sdk/resource/account_store_mapping.rb +0 -0
- data/lib/stormpath-sdk/resource/application.rb +5 -5
- data/lib/stormpath-sdk/resource/base.rb +0 -0
- data/lib/stormpath-sdk/resource/collection.rb +0 -0
- data/lib/stormpath-sdk/resource/custom_data.rb +0 -0
- data/lib/stormpath-sdk/resource/custom_data_hash_methods.rb +0 -0
- data/lib/stormpath-sdk/resource/custom_data_storage.rb +0 -0
- data/lib/stormpath-sdk/resource/directory.rb +1 -0
- data/lib/stormpath-sdk/resource/email_template.rb +0 -0
- data/lib/stormpath-sdk/resource/email_verification_token.rb +0 -0
- data/lib/stormpath-sdk/resource/error.rb +2 -3
- data/lib/stormpath-sdk/resource/expansion.rb +0 -0
- data/lib/stormpath-sdk/resource/group.rb +0 -0
- data/lib/stormpath-sdk/resource/group_membership.rb +0 -0
- data/lib/stormpath-sdk/resource/instance.rb +0 -0
- data/lib/stormpath-sdk/resource/oauth_policy.rb +0 -0
- data/lib/stormpath-sdk/resource/organization.rb +1 -1
- data/lib/stormpath-sdk/resource/organization_account_store_mapping.rb +0 -0
- data/lib/stormpath-sdk/resource/password_policy.rb +0 -0
- data/lib/stormpath-sdk/resource/password_reset_token.rb +0 -0
- data/lib/stormpath-sdk/resource/password_strength.rb +0 -0
- data/lib/stormpath-sdk/resource/refresh_token.rb +0 -0
- data/lib/stormpath-sdk/resource/tenant.rb +0 -0
- data/lib/stormpath-sdk/resource/utils.rb +0 -0
- data/lib/stormpath-sdk/resource/verification_email.rb +0 -0
- data/lib/stormpath-sdk/util/assert.rb +0 -0
- data/lib/stormpath-sdk/util/uri_builder.rb +38 -0
- data/lib/stormpath-sdk/version.rb +2 -2
- data/lib/stormpath-sdk.rb +47 -39
- data/spec/api_key_spec.rb +0 -0
- data/spec/auth/basic_authenticator_spec.rb +0 -0
- data/spec/auth/http_basic_authentication_spec.rb +86 -0
- data/spec/auth/http_bearer_authentication_spec.rb +86 -0
- data/spec/auth/sauthc1_signer_spec.rb +0 -0
- data/spec/cache/cache_entry_spec.rb +0 -0
- data/spec/cache/cache_spec.rb +0 -0
- data/spec/cache/cache_stats_spec.rb +0 -0
- data/spec/client_spec.rb +0 -0
- data/spec/data_store_spec.rb +40 -16
- data/spec/fixtures/response/create_saml_directory.json +0 -0
- data/spec/fixtures/response/create_saml_directory_mapping_rules.json +0 -0
- data/spec/fixtures/response/get_saml_directory_provider.json +0 -0
- data/spec/fixtures/response/get_saml_directory_provider_metadata.json +0 -0
- data/spec/oauth/access_token_authentication_result_spec.rb +8 -0
- data/spec/provider/account_resolver_spec.rb +0 -0
- data/spec/provider/provider_spec.rb +0 -0
- data/spec/resource/account_creation_policy_spec.rb +125 -2
- data/spec/resource/account_store_mapping_spec.rb +0 -0
- data/spec/resource/account_store_spec.rb +40 -13
- data/spec/resource/application_spec.rb +268 -51
- data/spec/resource/base_spec.rb +0 -0
- data/spec/resource/collection_spec.rb +60 -2
- data/spec/resource/custom_data_spec.rb +0 -0
- data/spec/resource/directory_spec.rb +82 -1
- data/spec/resource/email_template_spec.rb +0 -0
- data/spec/resource/expansion_spec.rb +0 -0
- data/spec/resource/group_membership_spec.rb +0 -0
- data/spec/resource/group_spec.rb +0 -0
- data/spec/resource/organization_spec.rb +37 -8
- data/spec/resource/password_policy_spec.rb +0 -0
- data/spec/resource/password_strength_spec.rb +0 -0
- data/spec/resource/status_spec.rb +0 -0
- data/spec/resource/tenant_spec.rb +0 -0
- data/spec/spec_helper.rb +5 -6
- data/spec/support/custom_data_storage_behavior.rb +0 -0
- data/spec/support/mocked_provider_accounts.rb +129 -117
- data/spec/support/resource_factory.rb +0 -0
- data/spec/support/resource_matchers.rb +7 -0
- data/spec/support/test_cache_stores.rb +0 -0
- data/spec/support/test_request_executor.rb +0 -0
- data/spec/util/uri_builder_spec.rb +47 -0
- data/stormpath-sdk.gemspec +1 -0
- data/support/api.rb +0 -0
- metadata +29 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Stormpath
|
|
2
|
+
module Oauth
|
|
3
|
+
class RemoteAccessTokenVerification
|
|
4
|
+
attr_reader :application, :app_href, :data_store, :access_token
|
|
5
|
+
|
|
6
|
+
def initialize(application, access_token)
|
|
7
|
+
@application = application
|
|
8
|
+
@app_href = application.href
|
|
9
|
+
@data_store = application.client.data_store
|
|
10
|
+
@access_token = access_token
|
|
11
|
+
validate_access_token
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def verify
|
|
15
|
+
data_store.get_resource("#{app_href}/authTokens/#{access_token}", VerifyTokenResult)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def validate_access_token
|
|
19
|
+
raise Stormpath::Oauth::Error, :jwt_invalid unless decoded_jwt.second['stt'] == 'access'
|
|
20
|
+
raise Stormpath::Oauth::Error, :jwt_invalid unless decoded_jwt.first['iss'] == application.href
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def decoded_jwt
|
|
24
|
+
@decoded_jwt ||= JWT.decode(access_token, application.client.data_store.api_key.secret)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Stormpath
|
|
2
|
+
module Oauth
|
|
3
|
+
class SocialGrant < Stormpath::Resource::Base
|
|
4
|
+
prop_accessor :grant_type, :provider_id, :code, :access_token
|
|
5
|
+
|
|
6
|
+
def form_properties
|
|
7
|
+
{
|
|
8
|
+
grant_type: grant_type,
|
|
9
|
+
providerId: provider_id,
|
|
10
|
+
code: code,
|
|
11
|
+
accessToken: access_token
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def set_options(request)
|
|
16
|
+
set_property :provider_id, request.provider_id
|
|
17
|
+
set_property :code, request.code if request.code
|
|
18
|
+
set_property :access_token, request.access_token if request.access_token
|
|
19
|
+
set_property :grant_type, request.grant_type
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def form_data?
|
|
23
|
+
true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Stormpath
|
|
2
|
+
module Oauth
|
|
3
|
+
class SocialGrantRequest
|
|
4
|
+
attr_accessor :grant_type, :provider_id, :code, :access_token
|
|
5
|
+
|
|
6
|
+
def initialize(provider_id, options = {})
|
|
7
|
+
@provider_id = provider_id.to_s
|
|
8
|
+
@code = options[:code]
|
|
9
|
+
@access_token = options[:access_token]
|
|
10
|
+
@grant_type = 'stormpath_social'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
module Stormpath
|
|
2
2
|
module Oauth
|
|
3
3
|
class StormpathGrantRequest
|
|
4
|
-
def initialize(account, application, api_key)
|
|
4
|
+
def initialize(account, application, api_key, status = :authenticated)
|
|
5
5
|
@account = account
|
|
6
6
|
@application = application
|
|
7
7
|
@api_key = api_key
|
|
8
|
+
@status = status.to_s.upcase
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def token
|
|
@@ -24,7 +25,7 @@ module Stormpath
|
|
|
24
25
|
sub: account.href,
|
|
25
26
|
iat: Time.now.to_i,
|
|
26
27
|
iss: application.href,
|
|
27
|
-
status:
|
|
28
|
+
status: @status,
|
|
28
29
|
aud: api_key.id
|
|
29
30
|
}
|
|
30
31
|
end
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
module Stormpath
|
|
2
2
|
module Oauth
|
|
3
3
|
class VerifyAccessToken
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
attr_reader :application, :verify_locally
|
|
5
|
+
|
|
6
|
+
def initialize(application, options = {})
|
|
7
|
+
@application = application
|
|
8
|
+
@verify_locally = options[:local] || false
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
def verify
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
def verify(access_token)
|
|
12
|
+
if verify_locally
|
|
13
|
+
LocalAccessTokenVerification.new(application, access_token).verify
|
|
14
|
+
else
|
|
15
|
+
RemoteAccessTokenVerification.new(application, access_token).verify
|
|
16
|
+
end
|
|
12
17
|
end
|
|
13
18
|
end
|
|
14
19
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -4,7 +4,9 @@ module Stormpath
|
|
|
4
4
|
prop_accessor(
|
|
5
5
|
:verification_email_status,
|
|
6
6
|
:verification_success_email_status,
|
|
7
|
-
:welcome_email_status
|
|
7
|
+
:welcome_email_status,
|
|
8
|
+
:email_domain_whitelist,
|
|
9
|
+
:email_domain_blacklist
|
|
8
10
|
)
|
|
9
11
|
|
|
10
12
|
has_many :verification_email_templates, class_name: :emailTemplate
|
|
File without changes
|
|
File without changes
|
|
@@ -14,17 +14,16 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
class Stormpath::Resource::AccountStore < Stormpath::Resource::Instance
|
|
17
|
-
|
|
18
|
-
|
|
19
17
|
def self.new(*args)
|
|
20
18
|
href = args.first[HREF_PROP_NAME]
|
|
21
|
-
if /directories
|
|
19
|
+
if href =~ /directories/
|
|
22
20
|
Stormpath::Resource::Directory.new(*args)
|
|
23
|
-
elsif /group
|
|
21
|
+
elsif href =~ /group/
|
|
24
22
|
Stormpath::Resource::Group.new(*args)
|
|
23
|
+
elsif href =~ /organizations/
|
|
24
|
+
Stormpath::Resource::Organization.new(*args)
|
|
25
25
|
else
|
|
26
|
-
raise
|
|
27
|
-
end
|
|
26
|
+
raise 'inappropriate type of an account store'
|
|
27
|
+
end
|
|
28
28
|
end
|
|
29
|
-
|
|
30
|
-
end
|
|
29
|
+
end
|
|
File without changes
|
|
@@ -18,7 +18,7 @@ class Stormpath::Resource::Application < Stormpath::Resource::Instance
|
|
|
18
18
|
include Stormpath::Resource::AccountOverrides
|
|
19
19
|
include UUIDTools
|
|
20
20
|
|
|
21
|
-
class LoadError <
|
|
21
|
+
class LoadError < ArgumentError; end
|
|
22
22
|
|
|
23
23
|
prop_accessor :name, :description, :authorized_callback_uris, :status
|
|
24
24
|
prop_reader :created_at, :modified_at
|
|
@@ -39,17 +39,17 @@ class Stormpath::Resource::Application < Stormpath::Resource::Instance
|
|
|
39
39
|
|
|
40
40
|
alias_method :oauth_policy, :o_auth_policy
|
|
41
41
|
|
|
42
|
-
def self.load
|
|
42
|
+
def self.load(composite_url)
|
|
43
43
|
begin
|
|
44
|
-
|
|
45
|
-
api_key_id, api_key_secret =
|
|
44
|
+
builder = Stormpath::Util::UriBuilder.new(composite_url)
|
|
45
|
+
api_key_id, api_key_secret = builder.userinfo.split(':')
|
|
46
46
|
|
|
47
47
|
client = Stormpath::Client.new api_key: {
|
|
48
48
|
id: api_key_id,
|
|
49
49
|
secret: api_key_secret
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
application_path = uri.path.slice(/\/applications(.)*$/)
|
|
52
|
+
application_path = builder.uri.path.slice(/\/applications(.)*$/)
|
|
53
53
|
client.applications.get(application_path)
|
|
54
54
|
rescue
|
|
55
55
|
raise LoadError
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -24,6 +24,7 @@ class Stormpath::Resource::Directory < Stormpath::Resource::Instance
|
|
|
24
24
|
|
|
25
25
|
has_many :accounts, can: [:get, :create]
|
|
26
26
|
has_many :groups, can: [:get, :create]
|
|
27
|
+
has_many :organizations, can: :get
|
|
27
28
|
has_one :custom_data
|
|
28
29
|
has_one :password_policy
|
|
29
30
|
has_one :account_creation_policy
|
|
File without changes
|
|
File without changes
|
|
@@ -14,10 +14,9 @@
|
|
|
14
14
|
# limitations under the License.
|
|
15
15
|
#
|
|
16
16
|
class Stormpath::Resource::Error < Stormpath::Resource::Base
|
|
17
|
+
prop_reader :status, :code, :message, :developer_message, :more_info, :request_id
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def initialize body
|
|
19
|
+
def initialize(body)
|
|
21
20
|
super body, nil
|
|
22
21
|
end
|
|
23
22
|
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
module Stormpath
|
|
3
|
+
module Util
|
|
4
|
+
class UriBuilder
|
|
5
|
+
attr_reader :composite_url, :escaped_url, :userinfo, :uri
|
|
6
|
+
|
|
7
|
+
def initialize(composite_url)
|
|
8
|
+
@composite_url = composite_url
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def escaped_url
|
|
12
|
+
@escaped_url ||= composite_url.gsub(userinfo_pattern, "://#{escaped_userinfo}@api")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def userinfo
|
|
16
|
+
@userinfo ||= composite_url.scan(userinfo_pattern).flatten.first
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def uri
|
|
20
|
+
begin
|
|
21
|
+
@uri ||= URI(escaped_url)
|
|
22
|
+
rescue URI::InvalidURIError
|
|
23
|
+
raise StandardError, 'Something is wrong with the composite url'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def escaped_userinfo
|
|
30
|
+
URI.escape(userinfo, '/')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def userinfo_pattern
|
|
34
|
+
/:\/\/(.*?)@api/
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/stormpath-sdk.rb
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
7
|
-
require
|
|
8
|
-
require
|
|
9
|
-
require
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'httpclient'
|
|
3
|
+
require 'multi_json'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
require 'open-uri'
|
|
6
|
+
require 'uri'
|
|
7
|
+
require 'uuidtools'
|
|
8
|
+
require 'jwt'
|
|
9
|
+
require 'yaml'
|
|
10
10
|
require 'active_support'
|
|
11
|
-
require
|
|
11
|
+
require 'active_support/core_ext'
|
|
12
12
|
require 'active_support/core_ext/module/delegation'
|
|
13
13
|
require 'active_support/core_ext/kernel/singleton_class'
|
|
14
14
|
require 'active_support/core_ext/array/wrap'
|
|
15
15
|
|
|
16
|
-
require
|
|
16
|
+
require 'stormpath-sdk/version' unless defined? Stormpath::VERSION
|
|
17
17
|
|
|
18
|
-
require
|
|
18
|
+
require 'stormpath-sdk/util/assert'
|
|
19
|
+
require 'stormpath-sdk/util/uri_builder'
|
|
19
20
|
|
|
20
21
|
module Stormpath
|
|
21
22
|
autoload :Error, 'stormpath-sdk/error'
|
|
@@ -66,21 +67,24 @@ module Stormpath
|
|
|
66
67
|
autoload :CacheStats, 'stormpath-sdk/cache/cache_stats'
|
|
67
68
|
autoload :MemoryStore, 'stormpath-sdk/cache/memory_store'
|
|
68
69
|
autoload :RedisStore, 'stormpath-sdk/cache/redis_store'
|
|
70
|
+
autoload :MemcachedStore, 'stormpath-sdk/cache/memcached_store'
|
|
69
71
|
autoload :DisabledCacheStore, 'stormpath-sdk/cache/disabled_cache_store'
|
|
70
72
|
end
|
|
71
73
|
|
|
72
74
|
module Authentication
|
|
73
|
-
autoload :UsernamePasswordRequest,
|
|
74
|
-
autoload :BasicLoginAttempt,
|
|
75
|
-
autoload :AuthenticationResult,
|
|
76
|
-
autoload :BasicAuthenticator,
|
|
75
|
+
autoload :UsernamePasswordRequest, 'stormpath-sdk/auth/username_password_request'
|
|
76
|
+
autoload :BasicLoginAttempt, 'stormpath-sdk/auth/basic_login_attempt'
|
|
77
|
+
autoload :AuthenticationResult, 'stormpath-sdk/auth/authentication_result'
|
|
78
|
+
autoload :BasicAuthenticator, 'stormpath-sdk/auth/basic_authenticator'
|
|
79
|
+
autoload :HttpBasicAuthentication, 'stormpath-sdk/auth/http_basic_authentication'
|
|
80
|
+
autoload :HttpBearerAuthentication, 'stormpath-sdk/auth/http_bearer_authentication'
|
|
77
81
|
end
|
|
78
82
|
|
|
79
83
|
module Provider
|
|
80
|
-
autoload :AccountResolver,
|
|
81
|
-
autoload :AccountAccess,
|
|
82
|
-
autoload :AccountResult,
|
|
83
|
-
autoload :AccountRequest,
|
|
84
|
+
autoload :AccountResolver, 'stormpath-sdk/provider/account_resolver'
|
|
85
|
+
autoload :AccountAccess, 'stormpath-sdk/provider/account_access'
|
|
86
|
+
autoload :AccountResult, 'stormpath-sdk/provider/account_result'
|
|
87
|
+
autoload :AccountRequest, 'stormpath-sdk/provider/account_request'
|
|
84
88
|
autoload :Provider, 'stormpath-sdk/provider/provider'
|
|
85
89
|
autoload :ProviderData, 'stormpath-sdk/provider/provider_data'
|
|
86
90
|
autoload :FacebookProvider, 'stormpath-sdk/provider/facebook/facebook_provider'
|
|
@@ -100,13 +104,13 @@ module Stormpath
|
|
|
100
104
|
end
|
|
101
105
|
|
|
102
106
|
module Http
|
|
103
|
-
autoload :Utils,
|
|
104
|
-
autoload :Request,
|
|
105
|
-
autoload :Response,
|
|
106
|
-
autoload :HttpClientRequestExecutor,
|
|
107
|
+
autoload :Utils, 'stormpath-sdk/http/utils'
|
|
108
|
+
autoload :Request, 'stormpath-sdk/http/request'
|
|
109
|
+
autoload :Response, 'stormpath-sdk/http/response'
|
|
110
|
+
autoload :HttpClientRequestExecutor, 'stormpath-sdk/http/http_client_request_executor'
|
|
107
111
|
|
|
108
112
|
module Authc
|
|
109
|
-
autoload :Sauthc1Signer,
|
|
113
|
+
autoload :Sauthc1Signer, 'stormpath-sdk/http/authc/sauthc1_signer'
|
|
110
114
|
end
|
|
111
115
|
end
|
|
112
116
|
|
|
@@ -115,20 +119,24 @@ module Stormpath
|
|
|
115
119
|
end
|
|
116
120
|
|
|
117
121
|
module Oauth
|
|
118
|
-
autoload :Authenticator,
|
|
119
|
-
autoload :PasswordGrant,
|
|
120
|
-
autoload :RefreshToken,
|
|
121
|
-
autoload :StormpathTokenGrant,
|
|
122
|
-
autoload :PasswordGrantRequest,
|
|
123
|
-
autoload :RefreshGrantRequest,
|
|
124
|
-
autoload :StormpathGrantRequest,
|
|
125
|
-
autoload :VerifyAccessToken,
|
|
126
|
-
autoload :
|
|
127
|
-
autoload :
|
|
122
|
+
autoload :Authenticator, 'stormpath-sdk/oauth/authenticator'
|
|
123
|
+
autoload :PasswordGrant, 'stormpath-sdk/oauth/password_grant'
|
|
124
|
+
autoload :RefreshToken, 'stormpath-sdk/oauth/refresh_token'
|
|
125
|
+
autoload :StormpathTokenGrant, 'stormpath-sdk/oauth/stormpath_token_grant'
|
|
126
|
+
autoload :PasswordGrantRequest, 'stormpath-sdk/oauth/password_grant_request'
|
|
127
|
+
autoload :RefreshGrantRequest, 'stormpath-sdk/oauth/refresh_grant_request'
|
|
128
|
+
autoload :StormpathGrantRequest, 'stormpath-sdk/oauth/stormpath_grant_request'
|
|
129
|
+
autoload :VerifyAccessToken, 'stormpath-sdk/oauth/verify_access_token'
|
|
130
|
+
autoload :RemoteAccessTokenVerification, 'stormpath-sdk/oauth/remote_access_token_verification'
|
|
131
|
+
autoload :LocalAccessTokenVerification, 'stormpath-sdk/oauth/local_access_token_verification'
|
|
132
|
+
autoload :VerifyTokenResult, 'stormpath-sdk/oauth/verify_token_result'
|
|
133
|
+
autoload :AccessTokenAuthenticationResult, 'stormpath-sdk/oauth/access_token_authentication_result'
|
|
128
134
|
autoload :Error, 'stormpath-sdk/oauth/error'
|
|
129
|
-
autoload :IdSiteGrantRequest,
|
|
130
|
-
autoload :IdSiteGrant,
|
|
131
|
-
autoload :ClientCredentialsGrantRequest,
|
|
132
|
-
autoload :ClientCredentialsGrant,
|
|
135
|
+
autoload :IdSiteGrantRequest, 'stormpath-sdk/oauth/id_site_grant_request'
|
|
136
|
+
autoload :IdSiteGrant, 'stormpath-sdk/oauth/id_site_grant'
|
|
137
|
+
autoload :ClientCredentialsGrantRequest, 'stormpath-sdk/oauth/client_credentials_grant_request'
|
|
138
|
+
autoload :ClientCredentialsGrant, 'stormpath-sdk/oauth/client_credentials_grant'
|
|
139
|
+
autoload :SocialGrantRequest, 'stormpath-sdk/oauth/social_grant_request'
|
|
140
|
+
autoload :SocialGrant, 'stormpath-sdk/oauth/social_grant'
|
|
133
141
|
end
|
|
134
142
|
end
|
data/spec/api_key_spec.rb
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'HttpBasicAuthentication', vcr: true do
|
|
4
|
+
let(:application) { test_api_client.applications.create(name: 'ruby sdk test app') }
|
|
5
|
+
let(:directory) { test_api_client.directories.create(name: random_directory_name) }
|
|
6
|
+
let(:account) do
|
|
7
|
+
application.accounts.create(
|
|
8
|
+
email: 'test@example.com',
|
|
9
|
+
given_name: 'Ruby SDK',
|
|
10
|
+
password: 'P@$$w0rd',
|
|
11
|
+
surname: 'SDK'
|
|
12
|
+
)
|
|
13
|
+
end
|
|
14
|
+
let(:api_key) { account.api_keys.create({}) }
|
|
15
|
+
let(:api_key_id) { api_key.id }
|
|
16
|
+
let(:api_key_secret) { api_key.secret }
|
|
17
|
+
let(:encoded_api_key) { Base64.encode64("#{api_key_id}:#{api_key_secret}") }
|
|
18
|
+
let(:basic_authorization_header) { "Basic #{encoded_api_key}" }
|
|
19
|
+
let(:authenticate) do
|
|
20
|
+
Stormpath::Authentication::HttpBasicAuthentication.new(application,
|
|
21
|
+
basic_authorization_header).authenticate!
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
before do
|
|
25
|
+
test_api_client.account_store_mappings.create(application: application,
|
|
26
|
+
account_store: directory,
|
|
27
|
+
list_index: 1,
|
|
28
|
+
is_default_account_store: true,
|
|
29
|
+
is_default_group_store: true)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
after do
|
|
33
|
+
account.delete
|
|
34
|
+
directory.delete
|
|
35
|
+
application.delete
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe 'with valid api key id and secret' do
|
|
39
|
+
it 'should return the apikey resource' do
|
|
40
|
+
expect(authenticate).to be_kind_of Stormpath::Resource::ApiKey
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'should return the account' do
|
|
44
|
+
expect(authenticate.account).to eq(account)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe 'with invalid api key id and secret' do
|
|
49
|
+
let(:encoded_api_key) { Base64.encode64('bad_api_key_id:bad_api_key_secret') }
|
|
50
|
+
|
|
51
|
+
it 'should raise error' do
|
|
52
|
+
expect do
|
|
53
|
+
authenticate
|
|
54
|
+
end.to raise_error(Stormpath::Error)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
describe 'with valid api key id and bad secret' do
|
|
59
|
+
let(:encoded_api_key) { Base64.encode64("#{api_key_id}:bad_api_key_secret") }
|
|
60
|
+
|
|
61
|
+
it 'should raise error' do
|
|
62
|
+
expect do
|
|
63
|
+
authenticate
|
|
64
|
+
end.to raise_error(Stormpath::Error)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe 'with no basic authorization header provided' do
|
|
69
|
+
let(:basic_authorization_header) { nil }
|
|
70
|
+
it 'should raise error' do
|
|
71
|
+
expect do
|
|
72
|
+
authenticate
|
|
73
|
+
end.to raise_error(Stormpath::Error)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
context 'with invalid authorization header type' do
|
|
78
|
+
let(:basic_authorization_header) { "Bearer #{encoded_api_key}" }
|
|
79
|
+
|
|
80
|
+
it 'should raise error' do
|
|
81
|
+
expect do
|
|
82
|
+
authenticate
|
|
83
|
+
end.to raise_error(Stormpath::Error)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|