stormpath-sdk 1.1.3 → 1.1.4
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/.travis.yml +1 -2
- data/CHANGES.md +7 -0
- data/README.md +24 -0
- data/lib/stormpath-sdk.rb +2 -0
- data/lib/stormpath-sdk/data_store.rb +1 -12
- data/lib/stormpath-sdk/http/http_client_request_executor.rb +0 -0
- data/lib/stormpath-sdk/http/request.rb +0 -0
- data/lib/stormpath-sdk/oauth/authenticator.rb +2 -1
- data/lib/stormpath-sdk/oauth/client_credentials_grant.rb +25 -0
- data/lib/stormpath-sdk/oauth/client_credentials_grant_request.rb +16 -0
- data/lib/stormpath-sdk/oauth/id_site_grant.rb +7 -0
- data/lib/stormpath-sdk/oauth/password_grant.rb +8 -0
- data/lib/stormpath-sdk/oauth/refresh_token.rb +7 -0
- data/lib/stormpath-sdk/oauth/stormpath_token_grant.rb +8 -1
- data/lib/stormpath-sdk/version.rb +1 -1
- data/spec/oauth/access_token_authentication_result_spec.rb +0 -0
- data/spec/resource/application_spec.rb +25 -0
- data/spec/resource/collection_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- data/stormpath-sdk.gemspec +5 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2840d5f55013463cc18377b9909e1f68840999b
|
4
|
+
data.tar.gz: fda3ed5eac3265a739fbdce2f05c3968e5527a84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c24a217cf341d9b23f38d8c27e68d944e6fb65659d350297f4d6d511dfe8a0ba59ea7b53fb60cd58e5edaf04cae75c38f0df5f9eed9c97742803671ea14f46
|
7
|
+
data.tar.gz: 842510b773d64d28890ba9f028555e4190592eb860b1f15d513fb6e8d19e2e303a7ed6a22043290e8c02bfd310caaa9a2f620c3c9c6bc186d42cfa6c8ac207f6
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -390,6 +390,30 @@ grant_request = Stormpath::Oauth::IdSiteGrantRequest.new jwt_token
|
|
390
390
|
response = application.authenticate_oauth grant_request
|
391
391
|
```
|
392
392
|
|
393
|
+
### Exchange Client Credentials for a Stormpath Access Token
|
394
|
+
|
395
|
+
As a developer, I want to authenticate API Keys directly against my application endpoint, so that I can have Stormpath generate an application token that I can use for a session.
|
396
|
+
|
397
|
+
Create an API Key for an account:
|
398
|
+
|
399
|
+
```ruby
|
400
|
+
account_api_key = account.api_keys.create({})
|
401
|
+
```
|
402
|
+
|
403
|
+
Then create an client credentials request and get a authentication result:
|
404
|
+
|
405
|
+
```ruby
|
406
|
+
client_credentials_grant_request = Stormpath::Oauth::ClientCredentialsGrantRequest.new(
|
407
|
+
account_api_key.id,
|
408
|
+
account_api_key.secret
|
409
|
+
)
|
410
|
+
|
411
|
+
authentication_result = application.authenticate_oauth(client_credentials_grant_request)
|
412
|
+
|
413
|
+
puts authentication_result.access_token
|
414
|
+
puts authentication_result.refresh_token
|
415
|
+
```
|
416
|
+
|
393
417
|
### Registering Accounts
|
394
418
|
|
395
419
|
Accounts are created on a directory instance. They can be created in two
|
data/lib/stormpath-sdk.rb
CHANGED
@@ -128,5 +128,7 @@ module Stormpath
|
|
128
128
|
autoload :Error, 'stormpath-sdk/oauth/error'
|
129
129
|
autoload :IdSiteGrantRequest, "stormpath-sdk/oauth/id_site_grant_request"
|
130
130
|
autoload :IdSiteGrant, "stormpath-sdk/oauth/id_site_grant"
|
131
|
+
autoload :ClientCredentialsGrantRequest, "stormpath-sdk/oauth/client_credentials_grant_request"
|
132
|
+
autoload :ClientCredentialsGrant, "stormpath-sdk/oauth/client_credentials_grant"
|
131
133
|
end
|
132
134
|
end
|
@@ -284,18 +284,7 @@ class Stormpath::DataStore
|
|
284
284
|
end
|
285
285
|
|
286
286
|
def form_request_parse(resource)
|
287
|
-
|
288
|
-
|
289
|
-
property_names = resource.get_dirty_property_names
|
290
|
-
property_names.each do |name|
|
291
|
-
if name != "formData"
|
292
|
-
property = resource.get_property name, ignore_camelcasing: true
|
293
|
-
data += name.underscore + '=' + property.to_s
|
294
|
-
data += '&' unless name == property_names.last
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
data
|
287
|
+
URI.encode_www_form(resource.form_properties.to_a)
|
299
288
|
end
|
300
289
|
|
301
290
|
def to_hash(resource)
|
File without changes
|
File without changes
|
@@ -22,7 +22,8 @@ module Stormpath
|
|
22
22
|
password: PasswordGrant,
|
23
23
|
refresh_token: RefreshToken,
|
24
24
|
id_site_token: IdSiteGrant,
|
25
|
-
stormpath_token: StormpathTokenGrant
|
25
|
+
stormpath_token: StormpathTokenGrant,
|
26
|
+
client_credentials: ClientCredentialsGrant
|
26
27
|
}.freeze
|
27
28
|
end
|
28
29
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Stormpath
|
2
|
+
module Oauth
|
3
|
+
class ClientCredentialsGrant < Stormpath::Resource::Base
|
4
|
+
prop_accessor :grant_type, :api_key_id, :api_key_secret
|
5
|
+
|
6
|
+
def form_properties
|
7
|
+
{
|
8
|
+
grant_type: grant_type,
|
9
|
+
apiKeyId: api_key_id,
|
10
|
+
apiKeySecret: api_key_secret
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_options(request)
|
15
|
+
set_property :api_key_id, request.api_key_id
|
16
|
+
set_property :api_key_secret, request.api_key_secret
|
17
|
+
set_property :grant_type, request.grant_type
|
18
|
+
end
|
19
|
+
|
20
|
+
def form_data?
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Stormpath
|
2
|
+
module Oauth
|
3
|
+
class ClientCredentialsGrantRequest
|
4
|
+
attr_reader :api_key_id, :api_key_secret
|
5
|
+
|
6
|
+
def initialize(api_key_id, api_key_secret)
|
7
|
+
@api_key_id = api_key_id
|
8
|
+
@api_key_secret = api_key_secret
|
9
|
+
end
|
10
|
+
|
11
|
+
def grant_type
|
12
|
+
'client_credentials'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,6 +3,13 @@ module Stormpath
|
|
3
3
|
class IdSiteGrant < Stormpath::Resource::Base
|
4
4
|
prop_accessor :grant_type, :token
|
5
5
|
|
6
|
+
def form_properties
|
7
|
+
{
|
8
|
+
grant_type: grant_type,
|
9
|
+
token: token
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
6
13
|
def set_options(request)
|
7
14
|
set_property :grant_type, request.grant_type
|
8
15
|
set_property :token, request.token
|
@@ -3,6 +3,14 @@ module Stormpath
|
|
3
3
|
class PasswordGrant < Stormpath::Resource::Base
|
4
4
|
prop_accessor :grant_type, :username, :password
|
5
5
|
|
6
|
+
def form_properties
|
7
|
+
{
|
8
|
+
grant_type: grant_type,
|
9
|
+
username: username,
|
10
|
+
password: password
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
6
14
|
def set_options(request)
|
7
15
|
set_property :username, request.username
|
8
16
|
set_property :password, request.password
|
@@ -3,6 +3,13 @@ module Stormpath
|
|
3
3
|
class RefreshToken < Stormpath::Resource::Base
|
4
4
|
prop_accessor :grant_type, :refresh_token
|
5
5
|
|
6
|
+
def form_properties
|
7
|
+
{
|
8
|
+
grant_type: grant_type,
|
9
|
+
refresh_token: refresh_token
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
6
13
|
def set_options(request)
|
7
14
|
set_property :refresh_token, request.refresh_token
|
8
15
|
set_property :grant_type, request.grant_type
|
@@ -1,7 +1,14 @@
|
|
1
1
|
module Stormpath
|
2
2
|
module Oauth
|
3
3
|
class StormpathTokenGrant < Stormpath::Resource::Base
|
4
|
-
prop_accessor :grant_type, :
|
4
|
+
prop_accessor :grant_type, :token
|
5
|
+
|
6
|
+
def form_properties
|
7
|
+
{
|
8
|
+
grant_type: grant_type,
|
9
|
+
token: token
|
10
|
+
}
|
11
|
+
end
|
5
12
|
|
6
13
|
def set_options(request)
|
7
14
|
set_property :token, request.token
|
File without changes
|
@@ -1082,6 +1082,31 @@ describe Stormpath::Resource::Application, :vcr do
|
|
1082
1082
|
end
|
1083
1083
|
end
|
1084
1084
|
|
1085
|
+
context 'generate access token from client credentials request' do
|
1086
|
+
let(:account_api_key) { account.api_keys.create({}) }
|
1087
|
+
|
1088
|
+
let(:client_credentials_grant_request) do
|
1089
|
+
Stormpath::Oauth::ClientCredentialsGrantRequest.new(
|
1090
|
+
account_api_key.id,
|
1091
|
+
account_api_key.secret
|
1092
|
+
)
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
let(:authenticate_oauth) { application.authenticate_oauth(client_credentials_grant_request) }
|
1096
|
+
|
1097
|
+
it 'should return access token response' do
|
1098
|
+
expect(authenticate_oauth).to be_kind_of(Stormpath::Oauth::AccessTokenAuthenticationResult)
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
it 'response should contain token data' do
|
1102
|
+
expect(authenticate_oauth.access_token).not_to be_empty
|
1103
|
+
expect(authenticate_oauth.refresh_token).not_to be_empty
|
1104
|
+
expect(authenticate_oauth.token_type).not_to be_empty
|
1105
|
+
expect(authenticate_oauth.expires_in).not_to be_nil
|
1106
|
+
expect(authenticate_oauth.stormpath_access_token_href).not_to be_empty
|
1107
|
+
end
|
1108
|
+
end
|
1109
|
+
|
1085
1110
|
context 'exchange id site token for access_token with invalid jwt' do
|
1086
1111
|
let(:invalid_jwt_token) { 'invalid_token' }
|
1087
1112
|
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
data/stormpath-sdk.gemspec
CHANGED
@@ -18,7 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency('multi_json', '>= 1.3.6')
|
19
19
|
s.add_dependency('httpclient', '>= 2.2.5')
|
20
20
|
s.add_dependency('uuidtools', '>= 2.1.3')
|
21
|
-
|
21
|
+
if RUBY_VERSION < '2.2.2'
|
22
|
+
s.add_dependency('activesupport', '>= 3.2.8', '< 5.0')
|
23
|
+
else
|
24
|
+
s.add_dependency('activesupport', '>= 3.2.8')
|
25
|
+
end
|
22
26
|
s.add_dependency('properties-ruby', "~> 0.0.4")
|
23
27
|
s.add_dependency('http-cookie', "~> 1.0.2")
|
24
28
|
s.add_dependency('java_properties')
|
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.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stormpath, Inc
|
@@ -314,6 +314,8 @@ files:
|
|
314
314
|
- lib/stormpath-sdk/id_site/id_site_result.rb
|
315
315
|
- lib/stormpath-sdk/oauth/access_token_authentication_result.rb
|
316
316
|
- lib/stormpath-sdk/oauth/authenticator.rb
|
317
|
+
- lib/stormpath-sdk/oauth/client_credentials_grant.rb
|
318
|
+
- lib/stormpath-sdk/oauth/client_credentials_grant_request.rb
|
317
319
|
- lib/stormpath-sdk/oauth/error.rb
|
318
320
|
- lib/stormpath-sdk/oauth/id_site_grant.rb
|
319
321
|
- lib/stormpath-sdk/oauth/id_site_grant_request.rb
|