cf-uaa-lib 1.3.2 → 1.3.3
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.
- data/.yardopts +5 -0
- data/Rakefile +0 -7
- data/cf-uaa-lib.gemspec +0 -2
- data/lib/uaa/http.rb +6 -3
- data/lib/uaa/misc.rb +2 -3
- data/lib/uaa/scim.rb +1 -2
- data/lib/uaa/token_coder.rb +23 -19
- data/lib/uaa/token_issuer.rb +3 -5
- data/lib/uaa/version.rb +1 -1
- data/spec/misc_spec.rb +1 -1
- metadata +5 -37
data/.yardopts
ADDED
data/Rakefile
CHANGED
@@ -13,7 +13,6 @@
|
|
13
13
|
require "rspec/core/rake_task"
|
14
14
|
require "bundler/gem_tasks" # only available in bundler >= 1.0.15
|
15
15
|
require "ci/reporter/rake/rspec"
|
16
|
-
require "yard"
|
17
16
|
|
18
17
|
ENV['CI_REPORTS'] = File.expand_path("spec_reports")
|
19
18
|
COV_REPORTS = File.expand_path("coverage")
|
@@ -22,12 +21,6 @@ task :default => [:test]
|
|
22
21
|
task :tests => [:test]
|
23
22
|
task :spec => [:test]
|
24
23
|
|
25
|
-
YARD::Rake::YardocTask.new do |t|
|
26
|
-
t.files = ['lib/**/*.rb', '-', 'LICENSE.TXT', 'NOTICE.TXT']
|
27
|
-
t.options = ['--main', 'README.md', '--no-private',
|
28
|
-
'--title', 'Cloud Foundry UAA Client API']
|
29
|
-
end
|
30
|
-
|
31
24
|
RSpec::Core::RakeTask.new("test") do |t|
|
32
25
|
t.rspec_opts = ["--format", "documentation", "--colour"]
|
33
26
|
t.pattern = "spec/**/*_spec.rb"
|
data/cf-uaa-lib.gemspec
CHANGED
@@ -36,8 +36,6 @@ Gem::Specification.new do |s|
|
|
36
36
|
|
37
37
|
s.add_development_dependency "bundler"
|
38
38
|
s.add_development_dependency "rake"
|
39
|
-
s.add_development_dependency "yard"
|
40
|
-
s.add_development_dependency "redcarpet"
|
41
39
|
s.add_development_dependency "rspec"
|
42
40
|
s.add_development_dependency "simplecov"
|
43
41
|
s.add_development_dependency "simplecov-rcov"
|
data/lib/uaa/http.rb
CHANGED
@@ -71,19 +71,22 @@ module Http
|
|
71
71
|
Base64.strict_encode64(str): [str].pack("m").gsub(/\n/, ''))
|
72
72
|
end
|
73
73
|
|
74
|
+
JSON_UTF8 = "application/json;charset=utf-8"
|
75
|
+
FORM_UTF8 = "application/x-www-form-urlencoded;charset=utf-8"
|
76
|
+
|
74
77
|
private
|
75
78
|
|
76
79
|
def json_get(target, path = nil, style = nil, headers = {})
|
77
80
|
raise ArgumentError unless style.nil? || style.is_a?(Symbol)
|
78
|
-
json_parse_reply(style, *http_get(target, path, headers.merge("accept" =>
|
81
|
+
json_parse_reply(style, *http_get(target, path, headers.merge("accept" => JSON_UTF8)))
|
79
82
|
end
|
80
83
|
|
81
84
|
def json_post(target, path, body, headers = {})
|
82
|
-
http_post(target, path, Util.json(body), headers.merge("content-type" =>
|
85
|
+
http_post(target, path, Util.json(body), headers.merge("content-type" => JSON_UTF8))
|
83
86
|
end
|
84
87
|
|
85
88
|
def json_put(target, path, body, headers = {})
|
86
|
-
http_put(target, path, Util.json(body), headers.merge("content-type" =>
|
89
|
+
http_put(target, path, Util.json(body), headers.merge("content-type" => JSON_UTF8))
|
87
90
|
end
|
88
91
|
|
89
92
|
def json_parse_reply(style, status, body, headers)
|
data/lib/uaa/misc.rb
CHANGED
@@ -98,9 +98,8 @@ class Misc
|
|
98
98
|
# @return [Hash]
|
99
99
|
def self.password_strength(target, password)
|
100
100
|
json_parse_reply(@key_style, *request(target, :post, '/password/score',
|
101
|
-
Util.encode_form(:password => password),
|
102
|
-
"
|
103
|
-
"accept" => "application/json"))
|
101
|
+
Util.encode_form(:password => password), "content-type" => Http::FORM_UTF8,
|
102
|
+
"accept" => Http::JSON_UTF8))
|
104
103
|
end
|
105
104
|
|
106
105
|
end
|
data/lib/uaa/scim.rb
CHANGED
@@ -209,9 +209,8 @@ class Scim
|
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
212
|
-
# Gets id/name pairs for given names.
|
212
|
+
# Gets id/name pairs for given names. For naming attribute of each object type see {Scim}
|
213
213
|
# @param type (see #add)
|
214
|
-
# @param [Array<String>] names. For naming attribute of each object type see {Scim}
|
215
214
|
# @return [Array] array of name/id hashes for each object found
|
216
215
|
def ids(type, *names)
|
217
216
|
na = type_info(type, :name_attr)
|
data/lib/uaa/token_coder.rb
CHANGED
@@ -46,8 +46,7 @@ class TokenCoder
|
|
46
46
|
|
47
47
|
# Constructs a signed JWT.
|
48
48
|
# @param token_body Contents of the token in any object that can be converted to JSON.
|
49
|
-
# @param
|
50
|
-
# @param pkey (see #initialize)
|
49
|
+
# @param options (see #initialize)
|
51
50
|
# @return [String] a signed JWT token string in the form "xxxx.xxxxx.xxxx".
|
52
51
|
def self.encode(token_body, options = {}, obsolete1 = nil, obsolete2 = nil)
|
53
52
|
unless options.is_a?(Hash) && obsolete1.nil? && obsolete2.nil?
|
@@ -78,9 +77,7 @@ class TokenCoder
|
|
78
77
|
# The JWT header indicates what signature algorithm was used and the
|
79
78
|
# corresponding key is used to verify the signature (if +verify+ is true).
|
80
79
|
# @param [String] token A JWT token as returned by {TokenCoder.encode}
|
81
|
-
# @param
|
82
|
-
# @param pkey (see #initialize)
|
83
|
-
# @param [Boolean] verify
|
80
|
+
# @param options (see #initialize)
|
84
81
|
# @return [Hash] the token contents
|
85
82
|
def self.decode(token, options = {}, obsolete1 = nil, obsolete2 = nil)
|
86
83
|
unless options.is_a?(Hash) && obsolete1.nil? && obsolete2.nil?
|
@@ -112,17 +109,26 @@ class TokenCoder
|
|
112
109
|
|
113
110
|
# Creates a new token en/decoder for a service that is associated with
|
114
111
|
# the the audience_ids, the symmetrical token validation key, and the
|
115
|
-
# public and/or private keys.
|
116
|
-
# @param [
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
112
|
+
# public and/or private keys.
|
113
|
+
# @param [Hash] options Supported options:
|
114
|
+
# * :audience_ids [Array<String>, String] -- An array or space separated
|
115
|
+
# string of values which indicate the token is intended for this service
|
116
|
+
# instance. It will be compared with tokens as they are decoded to ensure
|
117
|
+
# that the token was intended for this audience.
|
118
|
+
# * :skey [String] -- used to sign and validate tokens using symmetrical
|
119
|
+
# key algoruthms
|
120
|
+
# * :pkey [String, File, OpenSSL::PKey::PKey] -- may be a String or File in
|
121
|
+
# PEM or DER formats. May include public and/or private key data. The
|
122
|
+
# private key is used to sign tokens and the public key is used to
|
123
|
+
# validate tokens.
|
124
|
+
# * :algorithm [String] -- Sets default used for encoding. May be HS256,
|
125
|
+
# HS384, HS512, RS256, RS384, RS512, or none.
|
126
|
+
# * :verify [String] -- Verifies signatures when decoding tokens. Defaults
|
127
|
+
# to +true+.
|
128
|
+
# @note the TokenCoder instance must be configured with the appropriate
|
129
|
+
# key material to support particular algorithm families and operations
|
130
|
+
# -- i.e. :pkey must include a private key in order to sign tokens with
|
131
|
+
# the RS algorithms.
|
126
132
|
def initialize(options = {}, obsolete1 = nil, obsolete2 = nil)
|
127
133
|
unless options.is_a?(Hash) && obsolete1.nil? && obsolete2.nil?
|
128
134
|
# deprecated: def initialize(audience_ids, skey, pkey = nil)
|
@@ -135,10 +141,8 @@ class TokenCoder
|
|
135
141
|
|
136
142
|
# Encode a JWT token. Takes a hash of values to use as the token body.
|
137
143
|
# Returns a signed token in JWT format (header, body, signature).
|
138
|
-
# Algorithm may be HS256, HS384, HS512, RS256, RS384, RS512, or none --
|
139
|
-
# assuming the TokenCoder instance is configured with the appropriate
|
140
|
-
# key -- i.e. pkey must include a private key for the RS algorithms.
|
141
144
|
# @param token_body (see TokenCoder.encode)
|
145
|
+
# @param [String] algorithm -- overrides default. See {#initialize} for possible values.
|
142
146
|
# @return (see TokenCoder.encode)
|
143
147
|
def encode(token_body = {}, algorithm = nil)
|
144
148
|
token_body[:aud] = @options[:audience_ids] if @options[:audience_ids] && !token_body[:aud] && !token_body['aud']
|
data/lib/uaa/token_issuer.rb
CHANGED
@@ -72,8 +72,7 @@ class TokenIssuer
|
|
72
72
|
if scope = Util.arglist(params.delete(:scope))
|
73
73
|
params[:scope] = Util.strlist(scope)
|
74
74
|
end
|
75
|
-
headers = {'content-type' => '
|
76
|
-
'accept' => 'application/json',
|
75
|
+
headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8,
|
77
76
|
'authorization' => Http.basic_auth(@client_id, @client_secret) }
|
78
77
|
reply = json_parse_reply(@key_style, *request(@token_target, :post,
|
79
78
|
'/oauth/token', Util.encode_form(params), headers))
|
@@ -134,7 +133,7 @@ class TokenIssuer
|
|
134
133
|
uri = authorize_path_args("token", redir_uri, scope, state = random_state)
|
135
134
|
|
136
135
|
# the accept header is only here so the uaa will issue error replies in json to aid debugging
|
137
|
-
headers = {'content-type' =>
|
136
|
+
headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8 }
|
138
137
|
body = Util.encode_form(credentials.merge(:source => 'credentials'))
|
139
138
|
status, body, headers = request(@target, :post, uri, body, headers)
|
140
139
|
raise BadResponse, "status #{status}" unless status == 302
|
@@ -184,8 +183,7 @@ class TokenIssuer
|
|
184
183
|
# @param [String] redirect_uri (see #authcode_uri)
|
185
184
|
# @return (see #authcode_uri)
|
186
185
|
def autologin_uri(redirect_uri, credentials, scope = nil)
|
187
|
-
headers = {'content-type' => '
|
188
|
-
'accept' => 'application/json',
|
186
|
+
headers = {'content-type' => FORM_UTF8, 'accept' => JSON_UTF8,
|
189
187
|
'authorization' => Http.basic_auth(@client_id, @client_secret) }
|
190
188
|
body = Util.encode_form(credentials)
|
191
189
|
reply = json_parse_reply(nil, *request(@target, :post, "/autologin", body, headers))
|
data/lib/uaa/version.rb
CHANGED
data/spec/misc_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe Misc do
|
|
29
29
|
url.should == "https://uaa.cloudfoundry.com/login"
|
30
30
|
method.should == :get
|
31
31
|
headers["content-type"].should be_nil
|
32
|
-
headers["accept"].should =~ /application\/json/
|
32
|
+
headers["accept"].gsub(/\s/, '').should =~ /application\/json;charset=utf-8/i
|
33
33
|
[200, '{"commit_id":"12345","prompts":["one","two"]}', {"content-type" => "application/json"}]
|
34
34
|
end
|
35
35
|
result = Misc.server("https://uaa.cloudfoundry.com")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf-uaa-lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -63,38 +63,6 @@ dependencies:
|
|
63
63
|
- - ! '>='
|
64
64
|
- !ruby/object:Gem::Version
|
65
65
|
version: '0'
|
66
|
-
- !ruby/object:Gem::Dependency
|
67
|
-
name: yard
|
68
|
-
requirement: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- - ! '>='
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '0'
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
|
-
requirements:
|
79
|
-
- - ! '>='
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: redcarpet
|
84
|
-
requirement: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
|
-
requirements:
|
87
|
-
- - ! '>='
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
none: false
|
94
|
-
requirements:
|
95
|
-
- - ! '>='
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
98
66
|
- !ruby/object:Gem::Dependency
|
99
67
|
name: rspec
|
100
68
|
requirement: !ruby/object:Gem::Requirement
|
@@ -191,6 +159,7 @@ extensions: []
|
|
191
159
|
extra_rdoc_files: []
|
192
160
|
files:
|
193
161
|
- .gitignore
|
162
|
+
- .yardopts
|
194
163
|
- Gemfile
|
195
164
|
- LICENSE.TXT
|
196
165
|
- NOTICE.TXT
|
@@ -226,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
226
195
|
version: '0'
|
227
196
|
segments:
|
228
197
|
- 0
|
229
|
-
hash:
|
198
|
+
hash: 1871594390469590559
|
230
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
231
200
|
none: false
|
232
201
|
requirements:
|
@@ -235,12 +204,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
204
|
version: '0'
|
236
205
|
segments:
|
237
206
|
- 0
|
238
|
-
hash:
|
207
|
+
hash: 1871594390469590559
|
239
208
|
requirements: []
|
240
209
|
rubyforge_project: cf-uaa-lib
|
241
|
-
rubygems_version: 1.8.
|
210
|
+
rubygems_version: 1.8.24
|
242
211
|
signing_key:
|
243
212
|
specification_version: 3
|
244
213
|
summary: Client library for CloudFoundry UAA
|
245
214
|
test_files: []
|
246
|
-
has_rdoc:
|