doorkeeper 0.5.0 → 0.6.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (105) hide show
  1. data/.travis.yml +15 -6
  2. data/CHANGELOG.md +19 -1
  3. data/Gemfile +23 -7
  4. data/README.md +62 -27
  5. data/app/controllers/doorkeeper/application_controller.rb +1 -1
  6. data/app/controllers/doorkeeper/authorizations_controller.rb +45 -35
  7. data/app/controllers/doorkeeper/token_info_controller.rb +10 -9
  8. data/app/controllers/doorkeeper/tokens_controller.rb +13 -32
  9. data/app/validators/redirect_uri_validator.rb +11 -0
  10. data/app/views/doorkeeper/applications/_form.html.erb +6 -1
  11. data/app/views/doorkeeper/applications/edit.html.erb +2 -2
  12. data/app/views/doorkeeper/applications/new.html.erb +2 -2
  13. data/app/views/doorkeeper/applications/show.html.erb +4 -1
  14. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  15. data/app/views/doorkeeper/authorizations/new.html.erb +17 -17
  16. data/app/views/doorkeeper/authorizations/show.html.erb +4 -0
  17. data/config/locales/en.yml +10 -0
  18. data/doorkeeper.gemspec +3 -3
  19. data/lib/doorkeeper.rb +11 -2
  20. data/lib/doorkeeper/config.rb +6 -1
  21. data/lib/doorkeeper/errors.rb +15 -0
  22. data/lib/doorkeeper/helpers/controller.rb +24 -0
  23. data/lib/doorkeeper/models/access_grant.rb +1 -1
  24. data/lib/doorkeeper/models/access_token.rb +2 -3
  25. data/lib/doorkeeper/models/active_record/access_token.rb +6 -0
  26. data/lib/doorkeeper/models/mongo_mapper/access_grant.rb +28 -0
  27. data/lib/doorkeeper/models/mongo_mapper/access_token.rb +51 -0
  28. data/lib/doorkeeper/models/mongo_mapper/application.rb +30 -0
  29. data/lib/doorkeeper/models/mongo_mapper/revocable.rb +15 -0
  30. data/lib/doorkeeper/models/{mongoid → mongoid2}/access_grant.rb +1 -1
  31. data/lib/doorkeeper/models/{mongoid → mongoid2}/access_token.rb +6 -0
  32. data/lib/doorkeeper/models/{mongoid → mongoid2}/application.rb +2 -2
  33. data/lib/doorkeeper/models/mongoid3/access_grant.rb +22 -0
  34. data/lib/doorkeeper/models/mongoid3/access_token.rb +41 -0
  35. data/lib/doorkeeper/models/mongoid3/application.rb +22 -0
  36. data/lib/doorkeeper/oauth/authorization/code.rb +9 -17
  37. data/lib/doorkeeper/oauth/authorization/token.rb +8 -18
  38. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
  39. data/lib/doorkeeper/oauth/authorization_code_request.rb +82 -0
  40. data/lib/doorkeeper/oauth/client_credentials_request.rb +2 -4
  41. data/lib/doorkeeper/oauth/code_request.rb +28 -0
  42. data/lib/doorkeeper/oauth/code_response.rb +37 -0
  43. data/lib/doorkeeper/oauth/error_response.rb +23 -9
  44. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +4 -0
  45. data/lib/doorkeeper/oauth/password_access_token_request.rb +21 -65
  46. data/lib/doorkeeper/oauth/pre_authorization.rb +62 -0
  47. data/lib/doorkeeper/oauth/refresh_token_request.rb +58 -0
  48. data/lib/doorkeeper/oauth/token_request.rb +28 -0
  49. data/lib/doorkeeper/oauth/token_response.rb +29 -0
  50. data/lib/doorkeeper/rails/routes.rb +4 -3
  51. data/lib/doorkeeper/request.rb +33 -0
  52. data/lib/doorkeeper/request/authorization_code.rb +23 -0
  53. data/lib/doorkeeper/request/client_credentials.rb +23 -0
  54. data/lib/doorkeeper/request/code.rb +24 -0
  55. data/lib/doorkeeper/request/password.rb +23 -0
  56. data/lib/doorkeeper/request/refresh_token.rb +23 -0
  57. data/lib/doorkeeper/request/token.rb +24 -0
  58. data/lib/doorkeeper/server.rb +54 -0
  59. data/lib/doorkeeper/validations.rb +1 -0
  60. data/lib/doorkeeper/version.rb +1 -1
  61. data/lib/generators/doorkeeper/mongo_mapper/indexes_generator.rb +12 -0
  62. data/lib/generators/doorkeeper/templates/README +15 -1
  63. data/lib/generators/doorkeeper/templates/indexes.rb +3 -0
  64. data/lib/generators/doorkeeper/templates/initializer.rb +8 -1
  65. data/script/run_all +9 -9
  66. data/spec/controllers/authorizations_controller_spec.rb +8 -19
  67. data/spec/controllers/token_info_controller_spec.rb +9 -9
  68. data/spec/controllers/tokens_controller_spec.rb +2 -1
  69. data/spec/dummy/app/models/user.rb +11 -4
  70. data/spec/dummy/config/application.rb +8 -1
  71. data/spec/dummy/config/boot.rb +1 -1
  72. data/spec/dummy/config/initializers/doorkeeper.rb +9 -1
  73. data/spec/dummy/config/mongo.yml +11 -0
  74. data/spec/dummy/config/{mongoid.yml → mongoid2.yml} +3 -1
  75. data/spec/dummy/config/mongoid3.yml +18 -0
  76. data/spec/generators/install_generator_spec.rb +1 -0
  77. data/spec/lib/oauth/authorization_code_request_spec.rb +80 -0
  78. data/spec/lib/oauth/client_credentials_request_spec.rb +1 -3
  79. data/spec/lib/oauth/code_request_spec.rb +44 -0
  80. data/spec/lib/oauth/error_response_spec.rb +7 -7
  81. data/spec/lib/oauth/password_access_token_request_spec.rb +30 -143
  82. data/spec/lib/oauth/pre_authorization_spec.rb +80 -0
  83. data/spec/lib/oauth/refresh_token_request_spec.rb +56 -0
  84. data/spec/lib/oauth/token_request_spec.rb +46 -0
  85. data/spec/lib/oauth/{client_credentials/response_spec.rb → token_response_spec.rb} +13 -19
  86. data/spec/lib/server_spec.rb +24 -0
  87. data/spec/requests/endpoints/authorization_spec.rb +11 -27
  88. data/spec/requests/endpoints/token_spec.rb +17 -0
  89. data/spec/requests/flows/authorization_code_errors_spec.rb +0 -45
  90. data/spec/requests/flows/authorization_code_spec.rb +12 -2
  91. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  92. data/spec/requests/flows/password_spec.rb +1 -0
  93. data/spec/requests/flows/refresh_token_spec.rb +6 -4
  94. data/spec/spec_helper_integration.rb +4 -2
  95. data/spec/support/orm/mongo_mapper.rb +26 -0
  96. data/spec/support/orm/mongoid.rb +7 -2
  97. data/spec/validators/redirect_uri_validator_spec.rb +11 -4
  98. metadata +67 -42
  99. data/gemfiles/gemfile.rails-3.1.x +0 -17
  100. data/gemfiles/gemfile.rails-3.2.x +0 -17
  101. data/lib/doorkeeper/oauth/access_token_request.rb +0 -139
  102. data/lib/doorkeeper/oauth/authorization_request.rb +0 -114
  103. data/lib/doorkeeper/oauth/client_credentials/response.rb +0 -42
  104. data/spec/lib/oauth/access_token_request_spec.rb +0 -246
  105. data/spec/lib/oauth/authorization_request_spec.rb +0 -287
@@ -0,0 +1,23 @@
1
+ module Doorkeeper
2
+ module Request
3
+ class Password
4
+ def self.build(server)
5
+ new(server.client, server.resource_owner, server)
6
+ end
7
+
8
+ attr_accessor :client, :resource_owner, :server
9
+
10
+ def initialize(client, resource_owner, server)
11
+ @client, @resource_owner, @server = client, resource_owner, server
12
+ end
13
+
14
+ def request
15
+ @request ||= OAuth::PasswordAccessTokenRequest.new(Doorkeeper.configuration, client, resource_owner, server.parameters)
16
+ end
17
+
18
+ def authorize
19
+ request.authorize
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Doorkeeper
2
+ module Request
3
+ class RefreshToken
4
+ def self.build(server)
5
+ new(server.current_refresh_token, server.client)
6
+ end
7
+
8
+ attr_accessor :refresh_token, :client
9
+
10
+ def initialize(refresh_token, client)
11
+ @refresh_token, @client = refresh_token, client
12
+ end
13
+
14
+ def request
15
+ @request ||= OAuth::RefreshTokenRequest.new(Doorkeeper.configuration, refresh_token, client)
16
+ end
17
+
18
+ def authorize
19
+ request.authorize
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module Doorkeeper
2
+ module Request
3
+ class Token
4
+ # TODO: this is so wrong!
5
+ def self.build(server)
6
+ new(server.context.send(:pre_auth), server)
7
+ end
8
+
9
+ attr_accessor :pre_auth, :server
10
+
11
+ def initialize(pre_auth, server)
12
+ @pre_auth, @server = pre_auth, server
13
+ end
14
+
15
+ def request
16
+ @request ||= OAuth::TokenRequest.new(pre_auth, server.current_resource_owner)
17
+ end
18
+
19
+ def authorize
20
+ request.authorize
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,54 @@
1
+ module Doorkeeper
2
+ class Server
3
+ attr_accessor :context
4
+
5
+ def initialize(context = nil)
6
+ @context = context
7
+ end
8
+
9
+ def authorization_request(strategy)
10
+ klass = Request.authorization_strategy strategy
11
+ klass.build self
12
+ end
13
+
14
+ def token_request(strategy)
15
+ klass = Request.token_strategy strategy
16
+ klass.build self
17
+ end
18
+
19
+ # TODO: context should be the request
20
+ def parameters
21
+ context.request.parameters
22
+ end
23
+
24
+ def client
25
+ @client ||= OAuth::Client.authenticate(credentials)
26
+ end
27
+
28
+ def client_via_uid
29
+ @client_via_uid ||= OAuth::Client.find(parameters[:client_id])
30
+ end
31
+
32
+ def current_resource_owner
33
+ context.send :current_resource_owner
34
+ end
35
+
36
+ def current_refresh_token
37
+ Doorkeeper::AccessToken.by_refresh_token(parameters[:refresh_token])
38
+ end
39
+
40
+ def grant
41
+ Doorkeeper::AccessGrant.authenticate(parameters[:code])
42
+ end
43
+
44
+ # TODO: Use configuration and evaluate proper context on block
45
+ def resource_owner
46
+ context.send :resource_owner_from_credentials
47
+ end
48
+
49
+ def credentials
50
+ methods = Doorkeeper.configuration.client_credentials_methods
51
+ @credentials ||= OAuth::Client::Credentials.from_request(context.request, *methods)
52
+ end
53
+ end
54
+ end
@@ -13,6 +13,7 @@ module Doorkeeper
13
13
  end
14
14
 
15
15
  def valid?
16
+ validate
16
17
  @error.nil?
17
18
  end
18
19
 
@@ -1,3 +1,3 @@
1
1
  module Doorkeeper
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0.rc1"
3
3
  end
@@ -0,0 +1,12 @@
1
+ module Doorkeeper
2
+ module MongoMapper
3
+ class IndexesGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../../templates', __FILE__)
5
+ desc "Creates an indexes file for use with MongoMapper's rake db:index"
6
+
7
+ def install
8
+ template "indexes.rb", "db/indexes.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -17,12 +17,26 @@ And run
17
17
 
18
18
  rake db:migrate
19
19
 
20
- If you want to use Mongoid, configure the orm in initializers/doorkeeper.rb
20
+ If you want to use Mongoid, configure the orm in initializers/doorkeeper.rb:
21
21
 
22
+ # Mongoid
22
23
  Doorkeeper.configure do
23
24
  orm :mongoid
24
25
  end
25
26
 
27
+ If you want to use MongoMapper, configure the orm in
28
+ initializers/doorkeeper.rb:
29
+
30
+ # MongoMapper
31
+ Doorkeeper.configure do
32
+ orm :mongo_mapper
33
+ end
34
+
35
+ And run
36
+
37
+ rails generate doorkeeper:mongo_mapper:indexes
38
+ rake db:index
39
+
26
40
  Step 3.
27
41
  That's it, that's all. Enjoy!
28
42
 
@@ -0,0 +1,3 @@
1
+ Doorkeeper::Application.create_indexes
2
+ Doorkeeper::AccessGrant.create_indexes
3
+ Doorkeeper::AccessToken.create_indexes
@@ -1,6 +1,6 @@
1
1
  Doorkeeper.configure do
2
2
  # Change the ORM that doorkeeper will use.
3
- # Currently supported options are :active_record and :mongoid
3
+ # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
4
4
  orm :active_record
5
5
 
6
6
  # This block will be called to check whether the resource owner is authenticated or not.
@@ -54,4 +54,11 @@ Doorkeeper.configure do
54
54
  # falls back to the `:access_token` or `:bearer_token` params from the `params` object.
55
55
  # Check out the wiki for mor information on customization
56
56
  # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
57
+
58
+ # Change the test redirect uri for client apps
59
+ # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
60
+ # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
61
+ # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
62
+ #
63
+ # test_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
57
64
  end
data/script/run_all CHANGED
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env bash
2
2
  set -e
3
3
 
4
- RBENV_VERSION=1.8.7-p352 bundle install --quiet
5
- RBENV_VERSION=1.8.7-p352 bundle exec rake
6
- RBENV_VERSION=1.8.7-p352 DOORKEEPER_ORM=mongoid bundle exec rake
4
+ rails=3.2.8 orm=active_record bundle install --quiet
5
+ rails=3.2.8 orm=active_record bundle exec rake
7
6
 
8
- RBENV_VERSION=1.9.2-p290 bundle install --quiet
9
- RBENV_VERSION=1.9.2-p290 bundle exec rake
10
- RBENV_VERSION=1.9.2-p290 DOORKEEPER_ORM=mongoid bundle exec rake
7
+ rails=3.2.8 orm=mongoid2 bundle install --quiet
8
+ rails=3.2.8 orm=mongoid2 bundle exec rake
11
9
 
12
- RBENV_VERSION=1.9.3-p0 bundle install --quiet
13
- RBENV_VERSION=1.9.3-p0 bundle exec rake
14
- RBENV_VERSION=1.9.3-p0 DOORKEEPER_ORM=mongoid bundle exec rake
10
+ rails=3.2.8 orm=mongoid3 bundle install --quiet
11
+ rails=3.2.8 orm=mongoid3 bundle exec rake
12
+
13
+ rails=3.2.8 orm=mongo_mapper bundle install --quiet
14
+ rails=3.2.8 orm=mongo_mapper bundle exec rake
@@ -101,31 +101,20 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
101
101
  describe "GET #new with errors" do
102
102
  before do
103
103
  default_scopes_exist :public
104
- get :new, :client_id => client.uid, :response_type => "token", :scope => "invalid", :redirect_uri => client.redirect_uri
104
+ get :new, :an_invalid => 'request'
105
105
  end
106
106
 
107
- it "redirects after authorization" do
108
- response.should be_redirect
109
- end
110
-
111
- it "redirects to client redirect uri" do
112
- response.location.should =~ %r[^#{client.redirect_uri}]
113
- end
114
-
115
- it "does not include access token in fragment" do
116
- fragments("access_token").should be_nil
107
+ it "does not redirect" do
108
+ response.should_not be_redirect
117
109
  end
118
110
 
119
- it "includes error in fragment" do
120
- fragments("error").should == "invalid_scope"
111
+ it 'renders error template' do
112
+ response.should render_template(:error)
121
113
  end
122
114
 
123
- it "includes error description in fragment" do
124
- fragments("error_description").should == translated_error_message(:invalid_scope)
125
- end
126
-
127
- it "does not issue any access token" do
128
- Doorkeeper::AccessToken.all.should be_empty
115
+ it 'does not issue any token' do
116
+ Doorkeeper::AccessGrant.count.should be 0
117
+ Doorkeeper::AccessToken.count.should be 0
129
118
  end
130
119
  end
131
120
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper_integration'
2
2
 
3
3
  describe Doorkeeper::TokenInfoController do
4
-
4
+
5
5
  describe "when requesting tokeninfo with valid token" do
6
6
 
7
7
  let(:doorkeeper_token) { FactoryGirl.create(:access_token) }
8
8
 
9
9
  before(:each) do
10
- controller.stub(:doorkeeper_token) { doorkeeper_token }
10
+ controller.stub(:doorkeeper_token) { doorkeeper_token }
11
11
  end
12
12
 
13
13
  def do_get
@@ -17,13 +17,13 @@ describe Doorkeeper::TokenInfoController do
17
17
  describe "successful request" do
18
18
 
19
19
  it "responds with tokeninfo" do
20
- do_get
20
+ do_get
21
21
  response.body.should eq doorkeeper_token.to_json
22
22
  end
23
23
 
24
24
  it "responds with a 200 status" do
25
- do_get
26
- response.status.should eq 200
25
+ do_get
26
+ response.status.should eq 200
27
27
  end
28
28
  end
29
29
 
@@ -33,19 +33,19 @@ describe Doorkeeper::TokenInfoController do
33
33
  end
34
34
  it "responds with 401 when doorkeeper_token is not valid" do
35
35
  do_get
36
- response.status.should eq 401
36
+ response.status.should eq 401
37
37
  end
38
38
 
39
39
  it "responds with 401 when doorkeeper_token is invalid, expired or revoked" do
40
40
  controller.stub(:doorkeeper_token => doorkeeper_token)
41
- doorkeeper_token.stub(:accessible? => false)
41
+ doorkeeper_token.stub(:accessible? => false)
42
42
  do_get
43
- response.status.should eq 401
43
+ response.status.should eq 401
44
44
  end
45
45
 
46
46
  it "responds body message for error" do
47
47
  do_get
48
- response.body.should eq Doorkeeper::OAuth::ErrorResponse.new(:name => :invalid_request, :status => :unauthorized).attributes.to_json
48
+ response.body.should eq Doorkeeper::OAuth::ErrorResponse.new(:name => :invalid_request, :status => :unauthorized).body.to_json
49
49
  end
50
50
  end
51
51
 
@@ -11,6 +11,7 @@ describe Doorkeeper::TokensController do
11
11
  end
12
12
 
13
13
  it "returns the authorization" do
14
+ pending 'verify need of these specs'
14
15
  token.should_receive(:authorization)
15
16
  post :create
16
17
  end
@@ -26,10 +27,10 @@ describe Doorkeeper::TokensController do
26
27
  end
27
28
 
28
29
  it "returns the error response" do
30
+ pending 'verify need of these specs'
29
31
  token.stub(:error_response => stub(:to_json => [], :status => :unauthorized))
30
32
  post :create
31
33
  response.status.should == 401
32
34
  end
33
35
  end
34
-
35
36
  end
@@ -1,9 +1,8 @@
1
- if defined? ActiveRecord
1
+ case DOORKEEPER_ORM
2
+ when :active_record
2
3
  class User < ActiveRecord::Base
3
4
  end
4
- end
5
-
6
- if defined? Mongoid
5
+ when :mongoid2, :mongoid3
7
6
  class User
8
7
  include Mongoid::Document
9
8
  include Mongoid::Timestamps
@@ -11,6 +10,14 @@ if defined? Mongoid
11
10
  field :name, :type => String
12
11
  field :password, :type => String
13
12
  end
13
+ when :mongo_mapper
14
+ class User
15
+ include MongoMapper::Document
16
+ timestamps!
17
+
18
+ key :name, String
19
+ key :password, String
20
+ end
14
21
  end
15
22
 
16
23
  class User
@@ -6,7 +6,14 @@ require "sprockets/railtie"
6
6
 
7
7
  Bundler.require :default
8
8
 
9
- require "#{DOORKEEPER_ORM}/railtie"
9
+ orm = if [:mongoid2, :mongoid3].include?(DOORKEEPER_ORM)
10
+ Mongoid.load!(File.join(File.dirname(File.expand_path(__FILE__)), "#{DOORKEEPER_ORM}.yml"))
11
+ :mongoid
12
+ else
13
+ DOORKEEPER_ORM
14
+ end
15
+
16
+ require "#{orm}/railtie"
10
17
 
11
18
  module Dummy
12
19
  class Application < Rails::Application
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- DOORKEEPER_ORM = (ENV['DOORKEEPER_ORM'] || :active_record).to_sym unless defined?(DOORKEEPER_ORM)
4
+ DOORKEEPER_ORM = (ENV['orm'] || :active_record).to_sym unless defined?(DOORKEEPER_ORM)
5
5
 
6
6
  $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,6 +1,6 @@
1
1
  Doorkeeper.configure do
2
2
  # Change the ORM that doorkeeper will use
3
- # Currently supported => :active_record, :mongoid
3
+ # Currently supported options are :active_record, :mongoid2, :mongoid3, :mongo_mapper
4
4
  orm DOORKEEPER_ORM
5
5
 
6
6
  # This block will be called to check whether the
@@ -51,4 +51,12 @@ Doorkeeper.configure do
51
51
  # fallsback to `:access_token` or `:bearer_token` from `params` object
52
52
  # Check out the wiki for mor information on customization
53
53
  # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
54
+
55
+
56
+ # Change the test redirect uri for client apps
57
+ # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
58
+ # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
59
+ # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
60
+ #
61
+ # test_redirect_uri 'urn:ietf:wg:oauth:2.0:oob'
54
62
  end
@@ -0,0 +1,11 @@
1
+ defaults: &defaults
2
+ host: 127.0.0.1
3
+ port: 27017
4
+
5
+ development:
6
+ <<: *defaults
7
+ database: doorkeeper-mongomapper-development
8
+
9
+ test:
10
+ <<: *defaults
11
+ database: doorkeeper-mongomapper-test-suite