omniauth-uaa-oauth2 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7fe4a29f5011900aff6fc87ce882a2f2ba441aa4
4
+ data.tar.gz: d7e147f3ad95e22019747f78b2dcaba4c60283b8
5
+ SHA512:
6
+ metadata.gz: e8c6cc4f46f1452d0aa18103f3577a743675803422c8859bb94780871e9f61d6759268471299e7505f3606ab1682e3c8d9685789f1458006c33bfba4a095db74
7
+ data.tar.gz: ef3331f8537c246c350802a6f51b719460cf1295d322c24bf51fcc4ecbb33fda918046269a8b976e9e63fb99d814fcbd49e8e444320659e2078807097ed7f287
@@ -0,0 +1,3 @@
1
+ *.swp
2
+ *.swo
3
+ *.gem
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+
6
+
7
+
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ source 'http://rubygems.org'
15
+
16
+ gem 'cf-uaa-lib', '~> 1.3.7'
17
+
18
+ gemspec
19
+
20
+ group :example do
21
+ gem 'sinatra'
22
+ end
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-uaa-oauth2 (0.0.3)
5
+ cf-uaa-lib (>= 1.3.1, < 2.0)
6
+ cf-uaa-lib (>= 1.3.1, < 2.0)
7
+ omniauth (~> 1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ cf-uaa-lib (1.3.7)
13
+ multi_json
14
+ diff-lcs (1.1.3)
15
+ hashie (2.0.5)
16
+ multi_json (1.6.0)
17
+ omniauth (1.1.4)
18
+ hashie (>= 1.2, < 3)
19
+ rack
20
+ rack (1.4.1)
21
+ rack-protection (1.2.0)
22
+ rack
23
+ rake (0.9.2.2)
24
+ rspec (2.6.0)
25
+ rspec-core (~> 2.6.0)
26
+ rspec-expectations (~> 2.6.0)
27
+ rspec-mocks (~> 2.6.0)
28
+ rspec-core (2.6.4)
29
+ rspec-expectations (2.6.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-mocks (2.6.0)
32
+ sinatra (1.3.3)
33
+ rack (~> 1.3, >= 1.3.6)
34
+ rack-protection (~> 1.2)
35
+ tilt (~> 1.3, >= 1.3.3)
36
+ tilt (1.3.3)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ cf-uaa-lib (~> 1.3.7)
43
+ omniauth-uaa-oauth2!
44
+ rake
45
+ rspec (~> 2.6.0)
46
+ sinatra
data/LICENSE ADDED
@@ -0,0 +1,320 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
203
+
204
+ =======================================================================
205
+
206
+
207
+ omniauth-uaa-oauth2 09012012
208
+
209
+ omniauth-uaa-oauth2 09012012 : includes a number of subcomponents with
210
+ separate copyright notices and license terms. The product that
211
+ includes this file does not necessarily use all the open source
212
+ subcomponents referred to below. Your use of the source
213
+ code for the these subcomponents is subject to the terms and
214
+ conditions of the following licenses.
215
+
216
+
217
+
218
+
219
+ SECTION 1: BSD-STYLE, MIT-STYLE, OR SIMILAR STYLE LICENSES
220
+
221
+ >>> launchy-2.1.2
222
+ >>> omniauth-1.1.1
223
+
224
+
225
+
226
+ SECTION 2: Apache License, V2.0
227
+
228
+ >>> omniauth-uaa-oauth2-0.0.1
229
+
230
+
231
+
232
+
233
+
234
+
235
+ --------------- SECTION 1: BSD-STYLE, MIT-STYLE, OR SIMILAR STYLE LICENSES ----------
236
+
237
+ BSD-STYLE, MIT-STYLE, OR SIMILAR STYLE LICENSES are applicable to the following component(s).
238
+
239
+
240
+ >>> launchy-2.1.2
241
+
242
+ ISC LICENSE - http://opensource.org/licenses/isc-license.txt
243
+
244
+ Copyright (c) 2007-2011 Jeremy Hinegardner
245
+
246
+ Permission to use, copy, modify, and/or distribute this software for any
247
+ purpose with or without fee is hereby granted, provided that the above
248
+ copyright notice and this permission notice appear in all copies.
249
+
250
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
251
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
252
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
253
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
254
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
255
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
256
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
257
+
258
+
259
+ >>> omniauth-1.1.1
260
+
261
+ Copyright (c) 2010-2011 Michael Bleigh and Intridea, Inc.
262
+
263
+ Permission is hereby granted, free of charge, to any person obtaining a copy
264
+ of this software and associated documentation files (the "Software"), to deal
265
+ in the Software without restriction, including without limitation the rights
266
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
267
+ copies of the Software, and to permit persons to whom the Software is
268
+ furnished to do so, subject to the following conditions:
269
+
270
+ The above copyright notice and this permission notice shall be included in
271
+ all copies or substantial portions of the Software.
272
+
273
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
274
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
275
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
276
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
277
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
278
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
279
+ THE SOFTWARE.
280
+
281
+
282
+ --------------- SECTION 2: Apache License, V2.0 ----------
283
+
284
+ Apache License, V2.0 is applicable to the following component(s).
285
+
286
+
287
+ >>> omniauth-uaa-oauth2-0.0.1
288
+
289
+ omniauth-uaa-oauth2 v0.0.1
290
+ Copyright (c) 2012 VMware, Inc. All Rights Reserved.
291
+
292
+ This product is licensed to you under the Apache License, Version 2.0 (the "License").
293
+ You may not use this product except in compliance with the License.
294
+
295
+ This product may include a number of subcomponents with separate copyright notices
296
+ and license terms. Your use of these subcomponents is subject to the terms and
297
+ conditions of the subcomponent's license, as noted in the LICENSE file.
298
+
299
+
300
+
301
+ ===========================================================================
302
+
303
+ To the extent any open source components are licensed under the
304
+ GPL and/or LGPL, or other similar licenses that require the
305
+ source code and/or modifications to source code to be made
306
+ available (as would be noted above), you may obtain a copy of
307
+ the source code corresponding to the binaries for such open
308
+ source components and modifications thereto, if any, (the
309
+ "Source Files"), by downloading the Source Files from VMware's website at
310
+ http://www.vmware.com/download/open_source.html, or by sending a request, with
311
+ your name and address to: VMware, Inc., 3401 Hillview Avenue,
312
+ Palo Alto, CA 94304,United States of America. All such
313
+ requests should clearly specify: OPEN SOURCE FILES REQUEST,
314
+ Attention General Counsel. VMware shall mail a copy of the
315
+ Source Files to you on a CD or equivalent physical medium. This
316
+ offer to obtain a copy of the Source Files is valid for three
317
+ years from the date you acquired this Software product. Alternatively,
318
+ the Source Files may accompany the VMware product.
319
+
320
+ [CFOMNIAUTHUAAOAUTH09012012NV120512]
data/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ omniauth-uaa-oauth2 09012012
2
+
3
+ Copyright (c) 2012 VMware, Inc. All Rights Reserved.
4
+
5
+ This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ You may not use this product except in compliance with the License.
7
+
8
+ This product may include a number of subcomponents with separate copyright notices
9
+ and license terms. Your use of these subcomponents is subject to the terms and
10
+ conditions of the subcomponent's license, as noted in the LICENSE file.
@@ -0,0 +1,30 @@
1
+ CloudFoundry UAA OmniAuth Strategy
2
+ ==================================
3
+
4
+ OmniAuth strategy for authenticating users using the CloudFoundry UAA server.
5
+
6
+ Set up a local ruby environment (so sudo not required):
7
+
8
+ $ rvm use 1.9.2
9
+
10
+ or
11
+
12
+ $ rbenv global 1.9.2-p180
13
+
14
+ see: https://rvm.io/ or http://rbenv.org/
15
+
16
+ Build and install the cf-uaa-lib gem located at https://github.com/cloudfoundry/cf-uaa-lib
17
+
18
+ Build the gem
19
+
20
+ $ bundle install
21
+ $ bundle exec gem build omniauth-uaa-oauth2.gemspec
22
+
23
+ Install it
24
+
25
+ $ gem install omniauth-uaa-oauth2-*.gem
26
+
27
+
28
+ See the examples folder for details on how to use it.
29
+
30
+ Warning: Unlike the omniauth-oauth2 gem, this gem does not support the oauth2 'state' security parameter.
@@ -0,0 +1,20 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ #!/usr/bin/env rake
15
+ require "bundler/gem_tasks"
16
+ require 'rspec/core/rake_task'
17
+
18
+ RSpec::Core::RakeTask.new(:spec)
19
+
20
+ task :default => :spec
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ # Run with "bundle exec rackup"
15
+
16
+ require 'rubygems'
17
+ require 'bundler'
18
+ require 'sinatra'
19
+ require 'omniauth'
20
+ require 'omniauth-uaa-oauth2'
21
+
22
+ class App < Sinatra::Base
23
+ get '/' do
24
+ <<-HTML
25
+ <ul>
26
+ <li><a href='/auth/cloudfoundry'>Sign in with Cloud Foundry</a></li>
27
+ </ul>
28
+ HTML
29
+ end
30
+
31
+ get '/auth/cloudfoundry/callback' do
32
+ content_type 'application/json'
33
+ request.env['omniauth.auth'].to_hash.to_json rescue "No Data"
34
+ end
35
+
36
+ get '/auth/failure' do
37
+ content_type 'text/plain'
38
+ request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
39
+ end
40
+ end
41
+
42
+ use Rack::Session::Cookie, :secret => ENV['RACK_COOKIE_SECRET']
43
+
44
+ use OmniAuth::Builder do
45
+ provider :cloudfoundry, 'app', 'appclientsecret', {:auth_server_url => "http://localhost:8080/uaa", :token_server_url => "http://localhost:8080/uaa"}
46
+ #provider :cloudfoundry, '<register your client>', '<register your client secret>', {:auth_server_url => "https://login.cloudfoundry.com", :token_server_url => "https://uaa.cloudfoundry.com"}
47
+ end
48
+
49
+ run App.new
@@ -0,0 +1,14 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ require "omniauth/cloudfoundry"
@@ -0,0 +1,14 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ require 'omniauth/strategies/cloudfoundry'
@@ -0,0 +1,153 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ require 'uaa'
15
+ require 'omniauth'
16
+ require 'timeout'
17
+ require 'securerandom'
18
+
19
+ module OmniAuth
20
+ module Strategies
21
+ class Cloudfoundry
22
+ include OmniAuth::Strategy
23
+
24
+ args [:client_id, :client_secret]
25
+
26
+ option :name, "cloudfoundry"
27
+ option :auth_server_url, nil
28
+ option :token_server_url, nil
29
+ option :scope, nil
30
+ option :async_calls, false
31
+
32
+ attr_accessor :access_token
33
+ attr_reader :token_issuer
34
+ attr_reader :auth_server_url
35
+ attr_reader :token_server_url
36
+
37
+
38
+ def client
39
+
40
+ unless @token_issuer
41
+ unless @auth_server_url
42
+ @auth_server_url ||= options.auth_server_url
43
+ unless @auth_server_url.start_with?("http")
44
+ @auth_server_url = "https://#{@auth_server_url}"
45
+ end
46
+ end
47
+
48
+ unless @token_server_url
49
+ @token_server_url = options.token_server_url || options.auth_server_url
50
+
51
+ unless @token_server_url.start_with?("http")
52
+ @token_server_url = "https://#{@token_server_url}"
53
+ end
54
+ end
55
+
56
+ @token_issuer ||= CF::UAA::TokenIssuer.new(@auth_server_url,
57
+ options.client_id,
58
+ options.client_secret,
59
+ {:token_target => @token_server_url})
60
+ log :info, "Client: #{options.client_id} auth_server: #{@auth_server_url} token_server: #{@token_server_url}"
61
+ @token_issuer.logger = OmniAuth.logger
62
+ end
63
+
64
+ @token_issuer
65
+ end
66
+
67
+ def callback_url
68
+ full_host + script_name + callback_path
69
+ end
70
+
71
+ def request_phase
72
+ authcode_uri = client.authcode_uri(callback_url, options.scope)
73
+ log :info, "Redirect URI #{authcode_uri}"
74
+ session['redir_uri'] = authcode_uri
75
+ redirect authcode_uri
76
+ end
77
+
78
+ def authorize_params
79
+ params = options.authorize_params.merge(options.authorize_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
80
+ if OmniAuth.config.test_mode
81
+ @env ||= {}
82
+ @env['rack.session'] ||= {}
83
+ end
84
+ params
85
+ end
86
+
87
+ def token_params
88
+ options.token_params.merge(options.token_options.inject({}){|h,k| h[k.to_sym] = options[k] if options[k]; h})
89
+ end
90
+
91
+ def callback_phase
92
+ log :info, "In callback phase #{request.query_string}"
93
+ self.access_token = build_access_token(request.query_string)
94
+ self.access_token = refresh(access_token) if expired?(access_token)
95
+ log :info, "Got access token #{access_token.inspect}"
96
+
97
+ super
98
+ end
99
+
100
+ credentials do
101
+ {
102
+ 'token' => access_token.info["access_token"],
103
+ 'refresh_token' => access_token.info["refresh_token"],
104
+ 'authorized_scopes' => access_token.info["scope"]
105
+ }
106
+ end
107
+
108
+ uid{ raw_info["user_id"] || raw_info["email"] }
109
+
110
+ info do
111
+ prune!({
112
+ :name => raw_info["name"],
113
+ :email => raw_info["email"],
114
+ :first_name => raw_info["given_name"],
115
+ :last_name => raw_info["family_name"]
116
+ })
117
+ end
118
+
119
+ extra do
120
+ hash = {}
121
+ hash[:raw_info] = raw_info unless skip_info?
122
+ prune! hash
123
+ end
124
+
125
+ def raw_info
126
+ @raw_info ||= CF::UAA::Misc.whoami(@token_server_url, self.access_token.auth_header)
127
+ end
128
+
129
+ def prune!(hash)
130
+ hash.delete_if do |_, value|
131
+ prune!(value) if value.is_a?(Hash)
132
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
133
+ end
134
+ end
135
+
136
+ def build_access_token(query_string)
137
+ log :info, "Fetching access token"
138
+ client.authcode_grant(session.delete('redir_uri'), query_string)
139
+ end
140
+
141
+ def refresh(access_token)
142
+ log :info, "Refreshing access token"
143
+ client.refresh_token_grant(access_token.info[:refresh_token])
144
+ end
145
+
146
+ def expired?(access_token)
147
+ access_token = access_token.auth_header if access_token.respond_to? :auth_header
148
+ expiry = CF::UAA::TokenCoder.decode(access_token.split()[1], nil, nil, false)[:expires_at]
149
+ expiry.is_a?(Integer) && expiry <= Time.now.to_i
150
+ end
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,18 @@
1
+ #--
2
+ # Cloud Foundry 2012.02.03 Beta
3
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
4
+ #
5
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
6
+ # You may not use this product except in compliance with the License.
7
+ #
8
+ # This product includes a number of subcomponents with
9
+ # separate copyright notices and license terms. Your use of these
10
+ # subcomponents is subject to the terms and conditions of the
11
+ # subcomponent's license, as noted in the LICENSE file.
12
+ #++
13
+
14
+ module OmniAuth
15
+ module Cloudfoundry
16
+ VERSION = "0.0.3"
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Cloud Foundry 2012.02.03 Beta
4
+ # Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved.
5
+ #
6
+ # This product is licensed to you under the Apache License, Version 2.0 (the "License").
7
+ # You may not use this product except in compliance with the License.
8
+ #
9
+ # This product includes a number of subcomponents with
10
+ # separate copyright notices and license terms. Your use of these
11
+ # subcomponents is subject to the terms and conditions of the
12
+ # subcomponent's license, as noted in the LICENSE file.
13
+ #
14
+
15
+ require File.expand_path('../lib/omniauth/uaa_oauth2/version', __FILE__)
16
+
17
+ Gem::Specification.new do |gem|
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'cf-uaa-lib', ['>= 1.3.1', '< 2.0']
20
+
21
+ gem.authors = ["Joel D'sa", "Dave Syer", "Dale Olds", "Vidya Valmikinathan", "Luke Taylor"]
22
+ gem.email = ["jdsa@vmware.com", "olds@vmware.com", "dsyer@vmware.com", "vidya@vmware.com", "ltaylor@vmware.com"]
23
+ gem.description = %q{An OmniAuth strategy for the Cloudfoundry UAA}
24
+ gem.summary = %q{An OmniAuth strategy for the Cloudfoundry UAA}
25
+ gem.homepage = ""
26
+
27
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
+ gem.files = `git ls-files`.split("\n")
29
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
30
+ gem.name = "omniauth-uaa-oauth2"
31
+ gem.require_paths = ["lib"]
32
+ gem.version = OmniAuth::Cloudfoundry::VERSION
33
+
34
+ gem.add_runtime_dependency 'cf-uaa-lib', ['>= 1.3.1', '< 2.0']
35
+
36
+ gem.add_development_dependency 'rspec', '~> 2.6.0'
37
+ gem.add_development_dependency 'rake'
38
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-uaa-oauth2'
3
+
4
+ describe OmniAuth::Strategies::Cloudfoundry do
5
+ def app; lambda{|env| [200, {}, ["Hello."]]} end
6
+
7
+ before :each do
8
+ OmniAuth.config.test_mode = true
9
+ @request = double('Request')
10
+ @request.stub(:params) { {} }
11
+ @request.stub(:cookies) { {} }
12
+ @request.stub(:env) { {} }
13
+ end
14
+
15
+ after do
16
+ OmniAuth.config.test_mode = false
17
+ end
18
+
19
+ subject do
20
+ args = ['app', 'appclientsecret', @options || {}].compact
21
+ OmniAuth::Strategies::Cloudfoundry.new(app, *args).tap do |strategy|
22
+ strategy.stub(:request) { @request }
23
+ end
24
+ end
25
+
26
+ describe '#callback_path' do
27
+ it 'has the correct callback path' do
28
+ subject.callback_path.should eq('/auth/cloudfoundry/callback')
29
+ end
30
+ end
31
+
32
+ describe 'set auth and token server' do
33
+ it 'should set the right auth and token server' do
34
+ @options = {:auth_server_url => 'https://login.cloudfoundry.com'}
35
+ subject.client
36
+ subject.auth_server_url.should eq('https://login.cloudfoundry.com')
37
+ subject.token_server_url.should eq('https://login.cloudfoundry.com')
38
+ end
39
+
40
+ it 'should set the right auth and token server if independently set' do
41
+ @options = {:auth_server_url => 'https://login.cloudfoundry.com', :token_server_url => 'https://uaa.cloudfoundry.com'}
42
+ subject.client
43
+ subject.auth_server_url.should eq('https://login.cloudfoundry.com')
44
+ subject.token_server_url.should eq('https://uaa.cloudfoundry.com')
45
+ end
46
+
47
+ it 'should set the right auth and token server' do
48
+ @options = {:auth_server_url => 'login.cloudfoundry.com'}
49
+ subject.client
50
+ subject.auth_server_url.should eq('https://login.cloudfoundry.com')
51
+ subject.token_server_url.should eq('https://login.cloudfoundry.com')
52
+ end
53
+ end
54
+
55
+ describe 'set scopes' do
56
+ it 'should set the right scopes if requested' do
57
+ @options = {:auth_server_url => 'https://login.cloudfoundry.com', :token_server_url => 'https://uaa.cloudfoundry.com', :scope => "openid cloud_controller.read"}
58
+ subject.client
59
+ subject.options[:scope].should eq("openid cloud_controller.read")
60
+ end
61
+
62
+ it 'should not set any scopes if not requested' do
63
+ @options = {:auth_server_url => 'https://login.cloudfoundry.com', :token_server_url => 'https://uaa.cloudfoundry.com'}
64
+ subject.client
65
+ subject.options[:scope].should eq(nil)
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-uaa-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Joel D'sa
8
+ - Dave Syer
9
+ - Dale Olds
10
+ - Vidya Valmikinathan
11
+ - Luke Taylor
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2014-02-07 00:00:00.000000000 Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: omniauth
19
+ requirement: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '1.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: cf-uaa-lib
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.3.1
38
+ - - <
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.1
48
+ - - <
49
+ - !ruby/object:Gem::Version
50
+ version: '2.0'
51
+ - !ruby/object:Gem::Dependency
52
+ name: cf-uaa-lib
53
+ requirement: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 1.3.1
58
+ - - <
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.1
68
+ - - <
69
+ - !ruby/object:Gem::Version
70
+ version: '2.0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.6.0
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ version: 2.6.0
85
+ - !ruby/object:Gem::Dependency
86
+ name: rake
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: An OmniAuth strategy for the Cloudfoundry UAA
100
+ email:
101
+ - jdsa@vmware.com
102
+ - olds@vmware.com
103
+ - dsyer@vmware.com
104
+ - vidya@vmware.com
105
+ - ltaylor@vmware.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - .gitignore
111
+ - .travis.yml
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE
115
+ - NOTICE
116
+ - README.md
117
+ - Rakefile
118
+ - examples/config.ru
119
+ - lib/omniauth-uaa-oauth2.rb
120
+ - lib/omniauth/cloudfoundry.rb
121
+ - lib/omniauth/strategies/cloudfoundry.rb
122
+ - lib/omniauth/uaa_oauth2/version.rb
123
+ - omniauth-uaa-oauth2.gemspec
124
+ - spec/omniauth/strategies/uaa_oauth2_spec.rb
125
+ - spec/spec_helper.rb
126
+ homepage: ''
127
+ licenses: []
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.0.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: An OmniAuth strategy for the Cloudfoundry UAA
149
+ test_files: []