cf-uaa-lib 2.0.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/uaa/token_coder.rb +13 -2
- data/lib/uaa/version.rb +1 -1
- data/spec/token_coder_spec.rb +19 -6
- metadata +126 -94
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# CloudFoundry UAA Gem
|
2
|
-
|
2
|
+
[![Build Status](https://travis-ci.org/cloudfoundry/cf-uaa-lib.png)](https://travis-ci.org/cloudfoundry/cf-uaa-lib)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/cf-uaa-lib.png)](http://badge.fury.io/rb/cf-uaa-lib)
|
4
4
|
|
5
5
|
Client gem for interacting with the [CloudFoundry UAA server](https://github.com/cloudfoundry/uaa)
|
data/lib/uaa/token_coder.rb
CHANGED
@@ -176,6 +176,18 @@ class TokenCoder
|
|
176
176
|
# @param [String] auth_header (see Scim.initialize#auth_header)
|
177
177
|
# @return (see TokenCoder.decode)
|
178
178
|
def decode(auth_header)
|
179
|
+
decode_at_reference_time(auth_header, Time.now.to_i)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Returns hash of values decoded from the token contents,
|
183
|
+
# taking reference_time as the comparison time for expiration. If the
|
184
|
+
# audience_ids were specified in the options to this instance (see #initialize)
|
185
|
+
# and the token does not contain one or more of those audience_ids, an
|
186
|
+
# AuthError will be raised. AuthError is raised if the token has expired.
|
187
|
+
# @param [String] auth_header (see Scim.initialize#auth_header)
|
188
|
+
# @param [Integer] reference_time
|
189
|
+
# @return (see TokenCoder.decode)
|
190
|
+
def decode_at_reference_time(auth_header, reference_time)
|
179
191
|
unless auth_header && (tkn = auth_header.split(' ')).length == 2 && tkn[0] =~ /^bearer$/i
|
180
192
|
raise InvalidTokenFormat, "invalid authentication header: #{auth_header}"
|
181
193
|
end
|
@@ -185,12 +197,11 @@ class TokenCoder
|
|
185
197
|
raise InvalidAudience, "invalid audience: #{auds}"
|
186
198
|
end
|
187
199
|
exp = reply[:exp] || reply['exp']
|
188
|
-
unless exp.is_a?(Integer) && exp >
|
200
|
+
unless exp.is_a?(Integer) && exp > reference_time
|
189
201
|
raise TokenExpired, "token expired"
|
190
202
|
end
|
191
203
|
reply
|
192
204
|
end
|
193
|
-
|
194
205
|
end
|
195
206
|
|
196
207
|
end
|
data/lib/uaa/version.rb
CHANGED
data/spec/token_coder_spec.rb
CHANGED
@@ -156,9 +156,25 @@ describe TokenCoder do
|
|
156
156
|
expect { subject.decode("bEaReR #{tkn}") }.to raise_exception(DecodeError)
|
157
157
|
end
|
158
158
|
|
159
|
-
|
160
|
-
|
161
|
-
|
159
|
+
context "when the implied expiration check is now" do
|
160
|
+
it "raises an error if the token has expired" do
|
161
|
+
tkn = subject.encode({'foo' => "bar", 'exp' => Time.now.to_i - 60 })
|
162
|
+
expect { subject.decode("bEaReR #{tkn}") }.to raise_exception(TokenExpired)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when an explicit time stamp is provided for the expiration check" do
|
167
|
+
it "raises an error if the token was expired at the specified time" do
|
168
|
+
tkn = subject.encode({'foo' => "bar", 'exp' => Time.now.to_i - 30 })
|
169
|
+
expect { subject.decode_at_reference_time("bEaReR #{tkn}", Time.now.to_i - 20) }.to raise_exception(TokenExpired)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "returns the decoded token if it was valid at the specified time" do
|
173
|
+
tkn = subject.encode({'foo' => "bar", 'exp' => Time.now.to_i - 30 })
|
174
|
+
result = subject.decode_at_reference_time("bEaReR #{tkn}", Time.now.to_i - 100)
|
175
|
+
result.should_not be_nil
|
176
|
+
result["foo"].should == "bar"
|
177
|
+
end
|
162
178
|
end
|
163
179
|
|
164
180
|
it "decodes a token without validation" do
|
@@ -166,10 +182,7 @@ describe TokenCoder do
|
|
166
182
|
info = TokenCoder.decode(token, :verify => false)
|
167
183
|
info["id"].should_not be_nil
|
168
184
|
info["email"].should == "olds@vmware.com"
|
169
|
-
#puts Time.at(info[:exp].to_i)
|
170
|
-
#BaseCli.pp info
|
171
185
|
end
|
172
|
-
|
173
186
|
end
|
174
187
|
|
175
188
|
end
|
metadata
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf-uaa-lib
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 2.1.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Dave Syer
|
9
14
|
- Dale Olds
|
10
15
|
- Joel D'sa
|
@@ -13,111 +18,135 @@ authors:
|
|
13
18
|
autorequire:
|
14
19
|
bindir: bin
|
15
20
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
|
22
|
+
date: 2014-04-15 00:00:00 Z
|
23
|
+
dependencies:
|
24
|
+
- !ruby/object:Gem::Dependency
|
19
25
|
name: multi_json
|
20
|
-
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
21
28
|
none: false
|
22
|
-
requirements:
|
23
|
-
- -
|
24
|
-
- !ruby/object:Gem::Version
|
25
|
-
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
hash: 3
|
33
|
+
segments:
|
34
|
+
- 0
|
35
|
+
version: "0"
|
26
36
|
type: :runtime
|
27
|
-
|
28
|
-
|
29
|
-
- !ruby/object:Gem::Dependency
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
30
39
|
name: bundler
|
31
|
-
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
32
42
|
none: false
|
33
|
-
requirements:
|
34
|
-
- -
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
37
50
|
type: :development
|
38
|
-
|
39
|
-
|
40
|
-
- !ruby/object:Gem::Dependency
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
41
53
|
name: rake
|
42
|
-
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
43
56
|
none: false
|
44
|
-
requirements:
|
45
|
-
- -
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
48
64
|
type: :development
|
49
|
-
|
50
|
-
|
51
|
-
- !ruby/object:Gem::Dependency
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
52
67
|
name: rspec
|
53
|
-
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
54
70
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
59
78
|
type: :development
|
60
|
-
|
61
|
-
|
62
|
-
- !ruby/object:Gem::Dependency
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
63
81
|
name: simplecov
|
64
|
-
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
65
84
|
none: false
|
66
|
-
requirements:
|
67
|
-
- -
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
70
92
|
type: :development
|
71
|
-
|
72
|
-
|
73
|
-
- !ruby/object:Gem::Dependency
|
93
|
+
version_requirements: *id005
|
94
|
+
- !ruby/object:Gem::Dependency
|
74
95
|
name: simplecov-rcov
|
75
|
-
|
96
|
+
prerelease: false
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
76
98
|
none: false
|
77
|
-
requirements:
|
78
|
-
- -
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
81
106
|
type: :development
|
82
|
-
|
83
|
-
|
84
|
-
- !ruby/object:Gem::Dependency
|
107
|
+
version_requirements: *id006
|
108
|
+
- !ruby/object:Gem::Dependency
|
85
109
|
name: ci_reporter
|
86
|
-
|
110
|
+
prerelease: false
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
87
112
|
none: false
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
92
120
|
type: :development
|
93
|
-
|
94
|
-
|
95
|
-
- !ruby/object:Gem::Dependency
|
121
|
+
version_requirements: *id007
|
122
|
+
- !ruby/object:Gem::Dependency
|
96
123
|
name: json_pure
|
97
|
-
|
124
|
+
prerelease: false
|
125
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
98
126
|
none: false
|
99
|
-
requirements:
|
100
|
-
- -
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
103
134
|
type: :development
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Authorization (UAA) server. The UAA is an OAuth2 Authorization Server so it can
|
108
|
-
be used by webapps and command line apps to obtain access tokens to act on behalf
|
109
|
-
of users. The tokens can then be used to access protected resources in a Resource
|
110
|
-
Server. This library is for use by UAA client applications or resource servers.
|
111
|
-
email:
|
135
|
+
version_requirements: *id008
|
136
|
+
description: Client library for interacting with the CloudFoundry User Account and Authorization (UAA) server. The UAA is an OAuth2 Authorization Server so it can be used by webapps and command line apps to obtain access tokens to act on behalf of users. The tokens can then be used to access protected resources in a Resource Server. This library is for use by UAA client applications or resource servers.
|
137
|
+
email:
|
112
138
|
- dsyer@vmware.com
|
113
139
|
- olds@vmware.com
|
114
140
|
- jdsa@vmware.com
|
115
141
|
- vidya@vmware.com
|
116
142
|
- ltaylor@vmware.com
|
117
143
|
executables: []
|
144
|
+
|
118
145
|
extensions: []
|
146
|
+
|
119
147
|
extra_rdoc_files: []
|
120
|
-
|
148
|
+
|
149
|
+
files:
|
121
150
|
- .gitignore
|
122
151
|
- .travis.yml
|
123
152
|
- .yardopts
|
@@ -145,34 +174,37 @@ files:
|
|
145
174
|
- spec/token_coder_spec.rb
|
146
175
|
- spec/token_issuer_spec.rb
|
147
176
|
homepage: https://github.com/cloudfoundry/cf-uaa-lib
|
148
|
-
licenses:
|
177
|
+
licenses:
|
149
178
|
- Apache 2.0
|
150
179
|
post_install_message:
|
151
180
|
rdoc_options: []
|
152
|
-
|
181
|
+
|
182
|
+
require_paths:
|
153
183
|
- lib
|
154
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
185
|
none: false
|
156
|
-
requirements:
|
157
|
-
- -
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
|
160
|
-
segments:
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
hash: 3
|
190
|
+
segments:
|
161
191
|
- 0
|
162
|
-
|
163
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
version: "0"
|
193
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
194
|
none: false
|
165
|
-
requirements:
|
166
|
-
- -
|
167
|
-
- !ruby/object:Gem::Version
|
168
|
-
|
169
|
-
segments:
|
195
|
+
requirements:
|
196
|
+
- - ">="
|
197
|
+
- !ruby/object:Gem::Version
|
198
|
+
hash: 3
|
199
|
+
segments:
|
170
200
|
- 0
|
171
|
-
|
201
|
+
version: "0"
|
172
202
|
requirements: []
|
203
|
+
|
173
204
|
rubyforge_project: cf-uaa-lib
|
174
|
-
rubygems_version: 1.8.
|
205
|
+
rubygems_version: 1.8.15
|
175
206
|
signing_key:
|
176
207
|
specification_version: 3
|
177
208
|
summary: Client library for CloudFoundry UAA
|
178
209
|
test_files: []
|
210
|
+
|