rack-oauth2 0.0.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/example/server/authorize.rb +55 -0
- data/example/server/token.rb +21 -0
- data/lib/rack/oauth2.rb +2 -0
- data/lib/rack/oauth2/server.rb +4 -0
- data/lib/rack/oauth2/server/abstract.rb +3 -0
- data/lib/rack/oauth2/server/abstract/handler.rb +20 -0
- data/lib/rack/oauth2/server/abstract/request.rb +28 -0
- data/lib/rack/oauth2/server/abstract/response.rb +13 -0
- data/lib/rack/oauth2/server/authorization.rb +66 -0
- data/lib/rack/oauth2/server/authorization/code.rb +39 -0
- data/lib/rack/oauth2/server/authorization/code_and_token.rb +37 -0
- data/lib/rack/oauth2/server/authorization/token.rb +41 -0
- data/lib/rack/oauth2/server/error.rb +43 -0
- data/lib/rack/oauth2/server/token.rb +64 -0
- data/lib/rack/oauth2/server/token/assertion.rb +30 -0
- data/lib/rack/oauth2/server/token/authorization_code.rb +36 -0
- data/lib/rack/oauth2/server/token/password.rb +35 -0
- data/lib/rack/oauth2/server/token/refresh_token.rb +30 -0
- data/spec/rack/oauth2_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +124 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 nov matake
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
= rack-oauth2
|
|
2
|
+
|
|
3
|
+
Currently working on OAuth Authorization/Resource Server implementation based on draft v.10
|
|
4
|
+
http://tools.ietf.org/html/draft-ietf-oauth-v2-10
|
|
5
|
+
|
|
6
|
+
== Note on Patches/Pull Requests
|
|
7
|
+
|
|
8
|
+
* Fork the project.
|
|
9
|
+
* Make your feature addition or bug fix.
|
|
10
|
+
* Add tests for it. This is important so I don't break it in a
|
|
11
|
+
future version unintentionally.
|
|
12
|
+
* Commit, do not mess with rakefile, version, or history.
|
|
13
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
|
15
|
+
|
|
16
|
+
== Copyright
|
|
17
|
+
|
|
18
|
+
Copyright (c) 2010 nov matake. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = 'rack-oauth2'
|
|
8
|
+
gem.summary = %Q{Rack Middleware for OAuth2 Client & Server}
|
|
9
|
+
gem.description = %Q{Rack Middleware for OAuth2 Client & Server, currently working on server code first.}
|
|
10
|
+
gem.email = 'nov@matake.jp'
|
|
11
|
+
gem.homepage = 'http://github.com/nov/rack-oauth2'
|
|
12
|
+
gem.authors = ['nov matake']
|
|
13
|
+
gem.add_dependency 'json'
|
|
14
|
+
gem.add_development_dependency 'rspec', '>= 1.2.9'
|
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
16
|
+
end
|
|
17
|
+
Jeweler::GemcutterTasks.new
|
|
18
|
+
rescue LoadError
|
|
19
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
require 'spec/rake/spectask'
|
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
31
|
+
spec.rcov = true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
task :spec => :check_dependencies
|
|
35
|
+
|
|
36
|
+
task :default => :spec
|
|
37
|
+
|
|
38
|
+
require 'rake/rdoctask'
|
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ''
|
|
41
|
+
|
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
43
|
+
rdoc.title = 'rack-oauth2 #{version}'
|
|
44
|
+
rdoc.rdoc_files.include('README*')
|
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
46
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.0
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'sinatra'
|
|
3
|
+
|
|
4
|
+
use Rack::Session::Cookie
|
|
5
|
+
|
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../lib'))
|
|
7
|
+
require 'rack/oauth2'
|
|
8
|
+
|
|
9
|
+
get '/oauth/authorize' do
|
|
10
|
+
authorization_endpoint = Rack::OAuth2::Server::Authorization.new(self)
|
|
11
|
+
response = authorization_endpoint.call(env)
|
|
12
|
+
case response.first
|
|
13
|
+
when 200
|
|
14
|
+
request = env['rack.oauth2.request']
|
|
15
|
+
# output form
|
|
16
|
+
<<-HTML
|
|
17
|
+
<form action="/oauth/authorize" method="post">
|
|
18
|
+
<input type="hidden" name="client_id" value="#{request.client_id}" />
|
|
19
|
+
<input type="hidden" name="redirect_uri" value="#{request.redirect_uri}" />
|
|
20
|
+
<input type="hidden" name="response_type" value="#{request.response_type}" />
|
|
21
|
+
<input type="hidden" name="approved" value="true" />
|
|
22
|
+
<input type="submit" value="allow">
|
|
23
|
+
</form>
|
|
24
|
+
<form action="/oauth/authorize" method="post">
|
|
25
|
+
<input type="hidden" name="client_id" value="#{request.client_id}" />
|
|
26
|
+
<input type="hidden" name="redirect_uri" value="#{request.redirect_uri}" />
|
|
27
|
+
<input type="hidden" name="response_type" value="#{request.response_type}" />
|
|
28
|
+
<input type="hidden" name="response_type" value="code" />
|
|
29
|
+
<input type="submit" value="deny">
|
|
30
|
+
</form>
|
|
31
|
+
HTML
|
|
32
|
+
else
|
|
33
|
+
response
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
post '/oauth/authorize' do
|
|
38
|
+
authorization_endpoint = Rack::OAuth2::Server::Authorization.new(self) do |request, response|
|
|
39
|
+
# allow everything
|
|
40
|
+
params = env['rack.request.form_hash']
|
|
41
|
+
if params['approved']
|
|
42
|
+
response.approve!
|
|
43
|
+
case request
|
|
44
|
+
when Rack::OAuth2::Server::Authorization::Code::Request
|
|
45
|
+
response.code = 'code'
|
|
46
|
+
when Rack::OAuth2::Server::Authorization::Token::Request
|
|
47
|
+
response.access_token = 'access_token'
|
|
48
|
+
response.expires_in = 3600
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
raise Rack::OAuth2::Server::Unauthorized.new(:access_denied, 'User rejected the requested access.')
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
authorization_endpoint.call(env)
|
|
55
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'sinatra'
|
|
3
|
+
|
|
4
|
+
use Rack::Session::Cookie
|
|
5
|
+
|
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../lib'))
|
|
7
|
+
require 'rack/oauth2'
|
|
8
|
+
|
|
9
|
+
use Rack::OAuth2::Server::Token do |request, response|
|
|
10
|
+
p request, request.required_params
|
|
11
|
+
# allow everything
|
|
12
|
+
response.access_token = 'access_token'
|
|
13
|
+
response.expires_in = 3600
|
|
14
|
+
response.refresh_token = 'refresh_token'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
get '/oauth/token' do
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
post '/oauth/token' do
|
|
21
|
+
end
|
data/lib/rack/oauth2.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'rack/auth/abstract/handler'
|
|
2
|
+
|
|
3
|
+
module Rack
|
|
4
|
+
module OAuth2
|
|
5
|
+
module Server
|
|
6
|
+
module Abstract
|
|
7
|
+
class Handler < Rack::Auth::AbstractHandler
|
|
8
|
+
attr_accessor :request, :response
|
|
9
|
+
|
|
10
|
+
def call(env)
|
|
11
|
+
@authenticator.call(@request, @response) if @authenticator
|
|
12
|
+
env['rack.oauth2.request'] = @request
|
|
13
|
+
env['rack.oauth2.response'] = @response
|
|
14
|
+
@response
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
module Abstract
|
|
5
|
+
class Request < Rack::Request
|
|
6
|
+
def initialize(env)
|
|
7
|
+
super
|
|
8
|
+
verify_required_params!
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def required_params
|
|
12
|
+
raise "Implement verify_required_params! in #{self.class}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def verify_required_params!
|
|
16
|
+
missing_params = []
|
|
17
|
+
required_params.each do |key|
|
|
18
|
+
missing_params << key unless params[key.to_s]
|
|
19
|
+
end
|
|
20
|
+
unless missing_params.empty?
|
|
21
|
+
raise BadRequest.new(:invalid_request, "'#{missing_params.join('\', \'')}' required")
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Authorization < Abstract::Handler
|
|
5
|
+
|
|
6
|
+
def call(env)
|
|
7
|
+
request = Request.new(env)
|
|
8
|
+
request.profile.new(@app, @realm, &@authenticator).call(env).finish
|
|
9
|
+
rescue Error => e
|
|
10
|
+
e.finish
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Abstract::Request
|
|
14
|
+
attr_accessor :response_type, :client_id, :redirect_uri, :scope, :state
|
|
15
|
+
|
|
16
|
+
def initialize(env)
|
|
17
|
+
super
|
|
18
|
+
@client_id = params['client_id']
|
|
19
|
+
@redirect_uri = URI.parse(params['redirect_uri']) rescue nil
|
|
20
|
+
@scope = Array(params['scope'].to_s.split(' '))
|
|
21
|
+
@state = params['state']
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def required_params
|
|
25
|
+
[:response_type, :client_id, :redirect_uri]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def profile
|
|
29
|
+
case params['response_type']
|
|
30
|
+
when 'code'
|
|
31
|
+
Code
|
|
32
|
+
when 'token'
|
|
33
|
+
Token
|
|
34
|
+
when 'token_and_code'
|
|
35
|
+
CodeAndToken
|
|
36
|
+
else
|
|
37
|
+
raise BadRequest.new(:unsupported_response_type, "'#{params['response_type']}' isn't supported.")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Response < Abstract::Response
|
|
43
|
+
attr_accessor :redirect_uri, :state, :approved
|
|
44
|
+
|
|
45
|
+
def initialize(request)
|
|
46
|
+
@redirect_uri = request.redirect_uri
|
|
47
|
+
@state = request.state
|
|
48
|
+
super
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def approved?
|
|
52
|
+
@approved
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def approve!
|
|
56
|
+
@approved = true
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
require 'rack/oauth2/server/authorization/code'
|
|
66
|
+
require 'rack/oauth2/server/authorization/token'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Authorization
|
|
5
|
+
class Code < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Authorization::Request
|
|
14
|
+
def initialize(env)
|
|
15
|
+
super
|
|
16
|
+
@response_type = 'code'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Response < Authorization::Response
|
|
21
|
+
attr_accessor :code
|
|
22
|
+
|
|
23
|
+
def finish
|
|
24
|
+
if approved?
|
|
25
|
+
query_params = Array(redirect_uri.query)
|
|
26
|
+
query_params << "code=#{URI.encode code}"
|
|
27
|
+
query_params << "state=#{URI.encode state}" if state
|
|
28
|
+
redirect_uri.query = query_params.join('&')
|
|
29
|
+
redirect redirect_uri.to_s
|
|
30
|
+
end
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Authorization
|
|
5
|
+
class CodeAndToken < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Authorization::Request
|
|
14
|
+
def initialize(env)
|
|
15
|
+
super
|
|
16
|
+
# TODO
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def requred_params
|
|
20
|
+
# TODO
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Response < Authorization::Response
|
|
25
|
+
def finish
|
|
26
|
+
if approved?
|
|
27
|
+
# TODO
|
|
28
|
+
end
|
|
29
|
+
super
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Authorization
|
|
5
|
+
class Token < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Authorization::Request
|
|
14
|
+
def initialize(env)
|
|
15
|
+
super
|
|
16
|
+
@response_type = 'token'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class Response < Authorization::Response
|
|
21
|
+
attr_accessor :access_token, :expires_in, :scope
|
|
22
|
+
|
|
23
|
+
def finish
|
|
24
|
+
if approved?
|
|
25
|
+
fragment = Array(redirect_uri.fragment)
|
|
26
|
+
fragment << "access_token=#{URI.encode access_token}"
|
|
27
|
+
fragment << "expires_in=#{URI.encode expires_in.to_s}" if expires_in
|
|
28
|
+
fragment << "scope=#{URI.encode Array(scope).join(' ')}" if scope
|
|
29
|
+
query_params << "state=#{URI.encode state}" if state
|
|
30
|
+
redirect_uri.fragment = fragment.join('&')
|
|
31
|
+
redirect redirect_uri.to_s
|
|
32
|
+
end
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
|
|
5
|
+
class Error < StandardError
|
|
6
|
+
attr_accessor :code, :error, :description, :uri, :state
|
|
7
|
+
|
|
8
|
+
def initialize(code, error, description, options = {})
|
|
9
|
+
@code = code
|
|
10
|
+
@error = error
|
|
11
|
+
@description = description
|
|
12
|
+
@uri = options[:uri]
|
|
13
|
+
@state = options[:state]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def finish
|
|
17
|
+
[code, {'Content-Type' => 'application/json'}, response.to_json]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def response
|
|
21
|
+
response = {:error => error}
|
|
22
|
+
response[:error_description] = description if description
|
|
23
|
+
response[:error_uri] = uri if uri
|
|
24
|
+
response[:state] = state if state
|
|
25
|
+
response
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Unauthorized < Error
|
|
30
|
+
def initialize(error, description, options = {})
|
|
31
|
+
super(401, error, description, options)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
class BadRequest < Error
|
|
36
|
+
def initialize(error, description, options = {})
|
|
37
|
+
super(400, error, description, options)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Token < Abstract::Handler
|
|
5
|
+
attr_accessor :grant_type, :optional_authentication
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
request = Request.new(env)
|
|
9
|
+
request.profile.new(@app, @realm, &@authenticator).call(env).finish
|
|
10
|
+
rescue Error => e
|
|
11
|
+
e.finish
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Request < Abstract::Request
|
|
15
|
+
attr_accessor :client_id, :client_secret, :code, :redirect_uri, :scope
|
|
16
|
+
|
|
17
|
+
def initialize(env)
|
|
18
|
+
super
|
|
19
|
+
@client_id = params['client_id']
|
|
20
|
+
@client_secret = params['client_secret']
|
|
21
|
+
@scope = Array(params['scope'].to_s.split(' '))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def required_params
|
|
25
|
+
[:grant_type, :client_id]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def profile(allow_no_profile = false)
|
|
29
|
+
case params['grant_type']
|
|
30
|
+
when 'authorization_code'
|
|
31
|
+
AuthorizationCode
|
|
32
|
+
when 'password'
|
|
33
|
+
Password
|
|
34
|
+
when 'assertion'
|
|
35
|
+
Assertion
|
|
36
|
+
when 'refresh_token'
|
|
37
|
+
RefreshToken
|
|
38
|
+
else
|
|
39
|
+
raise BadRequest.new(:unsupported_grant_type, "'#{params['invalid_grant']}' isn't supported.")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Response < Abstract::Response
|
|
45
|
+
attr_accessor :access_token, :expires_in, :refresh_token, :scope
|
|
46
|
+
|
|
47
|
+
def finish
|
|
48
|
+
response = {:access_token => access_token}
|
|
49
|
+
response[:expires_in] = expires_in if expires_in
|
|
50
|
+
response[:refresh_token] = refresh_token if refresh_token
|
|
51
|
+
response[:scope] = Array(scope).join(' ') if scope
|
|
52
|
+
[200, {'Content-Type' => "application/json"}, response.to_json]
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
require 'rack/oauth2/server/token/authorization_code'
|
|
62
|
+
require 'rack/oauth2/server/token/password'
|
|
63
|
+
require 'rack/oauth2/server/token/assertion'
|
|
64
|
+
require 'rack/oauth2/server/token/refresh_token'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Token
|
|
5
|
+
class Assertion < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Token::Request
|
|
14
|
+
def initialize(env)
|
|
15
|
+
# TODO
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def required_params
|
|
19
|
+
# TODO
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Response < Token::Response
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Token
|
|
5
|
+
class AuthorizationCode < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Token::Request
|
|
14
|
+
attr_accessor :client_id, :client_secret, :code, :redirect_uri, :scope
|
|
15
|
+
|
|
16
|
+
def initialize(env)
|
|
17
|
+
super
|
|
18
|
+
@grant_type = 'authorization_code'
|
|
19
|
+
@code = params['code']
|
|
20
|
+
@redirect_uri = URI.parse(params['redirect_uri']) rescue nil
|
|
21
|
+
@scope = Array(params['scope'].to_s.split(' '))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def required_params
|
|
25
|
+
super + [:code, :redirect_uri]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class Response < Token::Response
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Token
|
|
5
|
+
class Password < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Token::Request
|
|
14
|
+
attr_reader :username, :password
|
|
15
|
+
|
|
16
|
+
def initialize(env)
|
|
17
|
+
super
|
|
18
|
+
@grant_type = 'password'
|
|
19
|
+
@username = params['username']
|
|
20
|
+
@password = params['password']
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def required_params
|
|
24
|
+
super + [:username, :password]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class Response < Token::Response
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Rack
|
|
2
|
+
module OAuth2
|
|
3
|
+
module Server
|
|
4
|
+
class Token
|
|
5
|
+
class RefreshToken < Abstract::Handler
|
|
6
|
+
|
|
7
|
+
def call(env)
|
|
8
|
+
@request = Request.new(env)
|
|
9
|
+
@response = Response.new(request)
|
|
10
|
+
super
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Request < Token::Request
|
|
14
|
+
def initialize(env)
|
|
15
|
+
# TODO
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def required_params
|
|
19
|
+
# TODO
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Response < Token::Response
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
data/spec/spec.opts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rack-oauth2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 31
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.0.0
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- nov matake
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-09-13 00:00:00 +09:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: json
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 3
|
|
30
|
+
segments:
|
|
31
|
+
- 0
|
|
32
|
+
version: "0"
|
|
33
|
+
type: :runtime
|
|
34
|
+
version_requirements: *id001
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: rspec
|
|
37
|
+
prerelease: false
|
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
39
|
+
none: false
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
hash: 13
|
|
44
|
+
segments:
|
|
45
|
+
- 1
|
|
46
|
+
- 2
|
|
47
|
+
- 9
|
|
48
|
+
version: 1.2.9
|
|
49
|
+
type: :development
|
|
50
|
+
version_requirements: *id002
|
|
51
|
+
description: Rack Middleware for OAuth2 Client & Server, currently working on server code first.
|
|
52
|
+
email: nov@matake.jp
|
|
53
|
+
executables: []
|
|
54
|
+
|
|
55
|
+
extensions: []
|
|
56
|
+
|
|
57
|
+
extra_rdoc_files:
|
|
58
|
+
- LICENSE
|
|
59
|
+
- README.rdoc
|
|
60
|
+
files:
|
|
61
|
+
- .document
|
|
62
|
+
- .gitignore
|
|
63
|
+
- LICENSE
|
|
64
|
+
- README.rdoc
|
|
65
|
+
- Rakefile
|
|
66
|
+
- VERSION
|
|
67
|
+
- example/server/authorize.rb
|
|
68
|
+
- example/server/token.rb
|
|
69
|
+
- lib/rack/oauth2.rb
|
|
70
|
+
- lib/rack/oauth2/server.rb
|
|
71
|
+
- lib/rack/oauth2/server/abstract.rb
|
|
72
|
+
- lib/rack/oauth2/server/abstract/handler.rb
|
|
73
|
+
- lib/rack/oauth2/server/abstract/request.rb
|
|
74
|
+
- lib/rack/oauth2/server/abstract/response.rb
|
|
75
|
+
- lib/rack/oauth2/server/authorization.rb
|
|
76
|
+
- lib/rack/oauth2/server/authorization/code.rb
|
|
77
|
+
- lib/rack/oauth2/server/authorization/code_and_token.rb
|
|
78
|
+
- lib/rack/oauth2/server/authorization/token.rb
|
|
79
|
+
- lib/rack/oauth2/server/error.rb
|
|
80
|
+
- lib/rack/oauth2/server/token.rb
|
|
81
|
+
- lib/rack/oauth2/server/token/assertion.rb
|
|
82
|
+
- lib/rack/oauth2/server/token/authorization_code.rb
|
|
83
|
+
- lib/rack/oauth2/server/token/password.rb
|
|
84
|
+
- lib/rack/oauth2/server/token/refresh_token.rb
|
|
85
|
+
- spec/rack/oauth2_spec.rb
|
|
86
|
+
- spec/spec.opts
|
|
87
|
+
- spec/spec_helper.rb
|
|
88
|
+
has_rdoc: true
|
|
89
|
+
homepage: http://github.com/nov/rack-oauth2
|
|
90
|
+
licenses: []
|
|
91
|
+
|
|
92
|
+
post_install_message:
|
|
93
|
+
rdoc_options:
|
|
94
|
+
- --charset=UTF-8
|
|
95
|
+
require_paths:
|
|
96
|
+
- lib
|
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
|
+
none: false
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
hash: 3
|
|
103
|
+
segments:
|
|
104
|
+
- 0
|
|
105
|
+
version: "0"
|
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
|
+
none: false
|
|
108
|
+
requirements:
|
|
109
|
+
- - ">="
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
hash: 3
|
|
112
|
+
segments:
|
|
113
|
+
- 0
|
|
114
|
+
version: "0"
|
|
115
|
+
requirements: []
|
|
116
|
+
|
|
117
|
+
rubyforge_project:
|
|
118
|
+
rubygems_version: 1.3.7
|
|
119
|
+
signing_key:
|
|
120
|
+
specification_version: 3
|
|
121
|
+
summary: Rack Middleware for OAuth2 Client & Server
|
|
122
|
+
test_files:
|
|
123
|
+
- spec/rack/oauth2_spec.rb
|
|
124
|
+
- spec/spec_helper.rb
|