doorkeeper 0.3.0 → 0.4.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.
Files changed (176) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +8 -0
  4. data/CHANGELOG.md +98 -0
  5. data/Gemfile +6 -0
  6. data/README.md +42 -6
  7. data/app/controllers/doorkeeper/application_controller.rb +4 -11
  8. data/app/controllers/doorkeeper/applications_controller.rb +7 -1
  9. data/app/controllers/doorkeeper/authorizations_controller.rb +11 -1
  10. data/app/controllers/doorkeeper/authorized_applications_controller.rb +3 -3
  11. data/app/controllers/doorkeeper/tokens_controller.rb +19 -5
  12. data/app/models/doorkeeper/access_grant.rb +28 -0
  13. data/app/models/doorkeeper/access_token.rb +65 -0
  14. data/app/models/doorkeeper/application.rb +54 -0
  15. data/app/views/doorkeeper/applications/index.html.erb +1 -1
  16. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  17. data/app/views/doorkeeper/authorizations/new.html.erb +15 -15
  18. data/app/views/doorkeeper/authorized_applications/index.html.erb +1 -2
  19. data/config/locales/en.yml +3 -0
  20. data/doorkeeper.gemspec +28 -0
  21. data/gemfiles/gemfile.rails-3.1.x +7 -0
  22. data/gemfiles/gemfile.rails-3.2.x +7 -0
  23. data/lib/doorkeeper/config.rb +73 -12
  24. data/lib/doorkeeper/doorkeeper_for.rb +19 -15
  25. data/lib/doorkeeper/engine.rb +28 -0
  26. data/lib/doorkeeper/models/scopes.rb +13 -0
  27. data/lib/doorkeeper/oauth/access_token_request.rb +9 -20
  28. data/lib/doorkeeper/oauth/authorization/code.rb +1 -1
  29. data/lib/doorkeeper/oauth/authorization/token.rb +2 -2
  30. data/lib/doorkeeper/oauth/authorization_request.rb +18 -23
  31. data/lib/doorkeeper/oauth/client/credentials.rb +21 -0
  32. data/lib/doorkeeper/oauth/client/methods.rb +18 -0
  33. data/lib/doorkeeper/oauth/client.rb +27 -0
  34. data/lib/doorkeeper/oauth/client_credentials/creator.rb +29 -0
  35. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +35 -0
  36. data/lib/doorkeeper/oauth/client_credentials/response.rb +42 -0
  37. data/lib/doorkeeper/oauth/client_credentials/validation.rb +33 -0
  38. data/lib/doorkeeper/oauth/client_credentials_request.rb +46 -0
  39. data/lib/doorkeeper/oauth/error.rb +9 -0
  40. data/lib/doorkeeper/oauth/error_response.rb +30 -0
  41. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -2
  42. data/lib/doorkeeper/oauth/password_access_token_request.rb +130 -0
  43. data/lib/doorkeeper/oauth/scopes.rb +60 -0
  44. data/lib/doorkeeper/version.rb +1 -1
  45. data/lib/doorkeeper.rb +23 -3
  46. data/lib/generators/doorkeeper/install_generator.rb +1 -0
  47. data/lib/generators/doorkeeper/templates/initializer.rb +12 -7
  48. data/lib/generators/doorkeeper/templates/migration.rb +1 -1
  49. data/lib/generators/doorkeeper/views_generator.rb +15 -0
  50. data/script/rails +6 -0
  51. data/script/run_all +11 -0
  52. data/spec/controllers/applications_controller_spec.rb +18 -0
  53. data/spec/controllers/authorizations_controller_spec.rb +131 -0
  54. data/spec/controllers/protected_resources_controller_spec.rb +308 -0
  55. data/spec/controllers/tokens_controller_spec.rb +34 -0
  56. data/spec/dummy/Rakefile +7 -0
  57. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  58. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  59. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  60. data/spec/dummy/app/controllers/full_protected_resources_controller.rb +12 -0
  61. data/spec/dummy/app/controllers/home_controller.rb +17 -0
  62. data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +11 -0
  63. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  64. data/spec/dummy/app/models/user.rb +11 -0
  65. data/spec/dummy/app/views/home/index.html.erb +0 -0
  66. data/spec/dummy/app/views/layouts/application.html.erb +16 -0
  67. data/spec/dummy/config/application.rb +53 -0
  68. data/spec/dummy/config/boot.rb +10 -0
  69. data/spec/dummy/config/database.yml +15 -0
  70. data/spec/dummy/config/environment.rb +5 -0
  71. data/spec/dummy/config/environments/development.rb +30 -0
  72. data/spec/dummy/config/environments/production.rb +60 -0
  73. data/spec/dummy/config/environments/test.rb +39 -0
  74. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  75. data/spec/dummy/config/initializers/doorkeeper.rb +41 -0
  76. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  77. data/spec/dummy/config/initializers/session_store.rb +8 -0
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  79. data/spec/dummy/config/locales/doorkeeper.en.yml +5 -0
  80. data/spec/dummy/config/routes.rb +8 -0
  81. data/spec/dummy/config.ru +4 -0
  82. data/spec/dummy/db/migrate/20111122132257_create_users.rb +9 -0
  83. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +5 -0
  84. data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +42 -0
  85. data/spec/dummy/db/schema.rb +62 -0
  86. data/spec/dummy/public/404.html +26 -0
  87. data/spec/dummy/public/422.html +26 -0
  88. data/spec/dummy/public/500.html +26 -0
  89. data/spec/dummy/public/favicon.ico +0 -0
  90. data/spec/dummy/script/rails +6 -0
  91. data/spec/factories/access_grant.rb +9 -0
  92. data/spec/factories/access_token.rb +7 -0
  93. data/spec/factories/application.rb +6 -0
  94. data/spec/generators/install_generator_spec.rb +35 -0
  95. data/spec/generators/templates/routes.rb +3 -0
  96. data/spec/generators/views_generator_spec.rb +27 -0
  97. data/spec/lib/config_spec.rb +87 -0
  98. data/spec/lib/models/expirable_spec.rb +49 -0
  99. data/spec/lib/models/revocable_spec.rb +31 -0
  100. data/spec/lib/models/scopes_spec.rb +32 -0
  101. data/spec/lib/oauth/access_token_request_spec.rb +240 -0
  102. data/spec/lib/oauth/authorization/uri_builder_spec.rb +37 -0
  103. data/spec/lib/oauth/authorization_request_spec.rb +286 -0
  104. data/spec/lib/oauth/client/credentials_spec.rb +47 -0
  105. data/spec/lib/oauth/client/methods_spec.rb +54 -0
  106. data/spec/lib/oauth/client_credentials/creator_spec.rb +47 -0
  107. data/spec/lib/oauth/client_credentials/issuer_spec.rb +57 -0
  108. data/spec/lib/oauth/client_credentials/response_spec.rb +58 -0
  109. data/spec/lib/oauth/client_credentials/validation_spec.rb +29 -0
  110. data/spec/lib/oauth/client_credentials_integration_spec.rb +27 -0
  111. data/spec/lib/oauth/client_credentials_request_spec.rb +60 -0
  112. data/spec/lib/oauth/client_spec.rb +42 -0
  113. data/spec/lib/oauth/error_response_spec.rb +40 -0
  114. data/spec/lib/oauth/error_spec.rb +19 -0
  115. data/spec/lib/oauth/helpers/scope_checker_spec.rb +74 -0
  116. data/spec/lib/oauth/helpers/unique_token_spec.rb +38 -0
  117. data/spec/lib/oauth/helpers/uri_checker_spec.rb +64 -0
  118. data/spec/lib/oauth/password_access_token_request_spec.rb +152 -0
  119. data/spec/lib/oauth/scopes_spec.rb +115 -0
  120. data/spec/models/doorkeeper/access_grant_spec.rb +36 -0
  121. data/spec/models/doorkeeper/access_token_spec.rb +113 -0
  122. data/spec/models/doorkeeper/application_spec.rb +129 -0
  123. data/spec/requests/applications/applications_request_spec.rb +92 -0
  124. data/spec/requests/applications/authorized_applications_spec.rb +30 -0
  125. data/spec/requests/endpoints/authorization_spec.rb +63 -0
  126. data/spec/requests/endpoints/token_spec.rb +29 -0
  127. data/spec/requests/flows/authorization_code_errors_spec.rb +111 -0
  128. data/spec/requests/flows/authorization_code_spec.rb +125 -0
  129. data/spec/requests/flows/client_credentials_spec.rb +56 -0
  130. data/spec/requests/flows/implicit_grant_errors_spec.rb +31 -0
  131. data/spec/requests/flows/implicit_grant_spec.rb +19 -0
  132. data/spec/requests/flows/password_spec.rb +52 -0
  133. data/spec/requests/flows/refresh_token_spec.rb +66 -0
  134. data/spec/requests/flows/skip_authorization_spec.rb +40 -0
  135. data/spec/requests/protected_resources/private_api_spec.rb +43 -0
  136. data/spec/spec_helper.rb +1 -0
  137. data/spec/spec_helper_integration.rb +28 -0
  138. data/spec/support/dependencies/database_cleaner.rb +16 -0
  139. data/spec/support/dependencies/factory_girl.rb +5 -0
  140. data/spec/support/helpers/access_token_request_helper.rb +11 -0
  141. data/spec/support/helpers/authorization_request_helper.rb +32 -0
  142. data/spec/support/helpers/config_helper.rb +9 -0
  143. data/spec/support/helpers/model_helper.rb +45 -0
  144. data/spec/support/helpers/request_spec_helper.rb +72 -0
  145. data/spec/support/helpers/url_helper.rb +51 -0
  146. data/spec/support/shared/controllers_shared_context.rb +60 -0
  147. data/spec/support/shared/models_shared_examples.rb +44 -0
  148. metadata +163 -57
  149. data/app/controllers/doorkeeper/application_controller.rbc +0 -675
  150. data/app/controllers/doorkeeper/applications_controller.rbc +0 -954
  151. data/app/controllers/doorkeeper/authorizations_controller.rbc +0 -659
  152. data/app/controllers/doorkeeper/authorized_applications_controller.rbc +0 -393
  153. data/app/controllers/doorkeeper/tokens_controller.rbc +0 -423
  154. data/app/helpers/doorkeeper/application_helper.rbc +0 -127
  155. data/app/models/access_grant.rb +0 -31
  156. data/app/models/access_grant.rbc +0 -821
  157. data/app/models/access_token.rb +0 -70
  158. data/app/models/access_token.rbc +0 -979
  159. data/app/models/application.rb +0 -45
  160. data/app/models/application.rbc +0 -753
  161. data/config/initializers/form_errors.rbc +0 -272
  162. data/config/routes.rbc +0 -366
  163. data/lib/doorkeeper/config/scope.rb +0 -11
  164. data/lib/doorkeeper/config/scopes.rb +0 -61
  165. data/lib/doorkeeper/config/scopes_builder.rb +0 -18
  166. data/lib/doorkeeper/config.rbc +0 -1385
  167. data/lib/doorkeeper/doorkeeper_for.rbc +0 -1029
  168. data/lib/doorkeeper/engine.rbc +0 -318
  169. data/lib/doorkeeper/oauth/access_token_request.rbc +0 -2042
  170. data/lib/doorkeeper/oauth/authorization_request.rbc +0 -2272
  171. data/lib/doorkeeper/oauth/random_string.rbc +0 -437
  172. data/lib/doorkeeper/validations.rbc +0 -774
  173. data/lib/doorkeeper/version.rbc +0 -130
  174. data/lib/doorkeeper.rbc +0 -407
  175. data/lib/generators/doorkeeper/install_generator.rbc +0 -453
  176. data/lib/tasks/doorkeeper_tasks.rake.compiled.rbc +0 -40
@@ -0,0 +1,41 @@
1
+ Doorkeeper.configure do
2
+ # This block will be called to check whether the
3
+ # resource owner is authenticated or not
4
+ resource_owner_authenticator do |routes|
5
+ # Put your resource owner authentication logic here.
6
+ # If you want to use named routes from your app you need
7
+ # to call them on routes object eg.
8
+ # routes.new_user_session_path
9
+ # e.g. User.find_by_id(session[:user_id]) || redirect_to(routes.new_user_session_url)
10
+ User.find_by_id(session[:user_id]) || redirect_to(routes.root_url, :alert => "Needs sign in.")
11
+ end
12
+
13
+ # If you want to restrict the access to the web interface for
14
+ # adding oauth authorized applications you need to declare the
15
+ # block below
16
+ # admin_authenticator do |routes|
17
+ # # Put your admin authentication logic here.
18
+ # # If you want to use named routes from your app you need
19
+ # # to call them on routes object eg.
20
+ # # routes.new_admin_session_path
21
+ # Admin.find_by_id(session[:admin_id]) || redirect_to(routes.new_admin_session_url)
22
+ # end
23
+
24
+ # Access token expiration time (default 2 hours)
25
+ # If you want to disable expiration, set this to nil.
26
+ # access_token_expires_in 2.hours
27
+
28
+ # Issue access tokens with refresh token (disabled by default)
29
+ use_refresh_token
30
+
31
+ # Define access token scopes for your provider
32
+ # For more information go to https://github.com/applicake/doorkeeper/wiki/Using-Scopes
33
+ default_scopes :public
34
+ optional_scopes :write, :update
35
+
36
+ # Change the way client credentials are retrieved from the request object.
37
+ # By default it retrieves first from `HTTP_AUTHORIZATION` header and
38
+ # fallsback to `:client_id` and `:client_secret` from `params` object
39
+ # Check out the wiki for mor information on customization
40
+ # client_credentials :from_basic, :from_params
41
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'c00157b5a1bb6181792f0f4a8a080485de7bab9987e6cf159dc74c4f0573345c1bfa713b5d756e1491fc0b098567e8a619e2f8d268eda86a20a720d05d633780'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters :format => [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ en:
2
+ doorkeeper:
3
+ scopes:
4
+ public: "Access your public data"
5
+ write: "Update your data"
@@ -0,0 +1,8 @@
1
+ Rails.application.routes.draw do
2
+ mount Doorkeeper::Engine => "/oauth"
3
+ get '/callback', :to => "home#callback"
4
+ get '/sign_in', :to => "home#sign_in"
5
+ resources :semi_protected_resources
6
+ resources :full_protected_resources
7
+ root :to => "home#index"
8
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,9 @@
1
+ class CreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ class AddPasswordToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :password_digest, :string
4
+ end
5
+ end
@@ -0,0 +1,42 @@
1
+ class CreateDoorkeeperTables < ActiveRecord::Migration
2
+ def change
3
+ create_table :oauth_applications do |t|
4
+ t.string :name, :null => false
5
+ t.string :uid, :null => false
6
+ t.string :secret, :null => false
7
+ t.string :redirect_uri, :null => false
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :oauth_applications, :uid, :unique => true
12
+
13
+ create_table :oauth_access_grants do |t|
14
+ t.integer :resource_owner_id, :null => false
15
+ t.integer :application_id, :null => false
16
+ t.string :token, :null => false
17
+ t.integer :expires_in, :null => false
18
+ t.string :redirect_uri, :null => false
19
+ t.datetime :created_at, :null => false
20
+ t.datetime :revoked_at
21
+ t.string :scopes
22
+ end
23
+
24
+ add_index :oauth_access_grants, :token, :unique => true
25
+
26
+ create_table :oauth_access_tokens do |t|
27
+ t.integer :resource_owner_id
28
+ t.integer :application_id, :null => false
29
+ t.string :token, :null => false
30
+ t.string :refresh_token
31
+ t.integer :expires_in
32
+ t.datetime :revoked_at
33
+ t.datetime :created_at, :null => false
34
+ t.string :scopes
35
+ end
36
+
37
+ add_index :oauth_access_tokens, :token, :unique => true
38
+ add_index :oauth_access_tokens, :resource_owner_id
39
+ add_index :oauth_access_tokens, :refresh_token, :unique => true
40
+
41
+ end
42
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120524202412) do
15
+
16
+ create_table "oauth_access_grants", :force => true do |t|
17
+ t.integer "resource_owner_id", :null => false
18
+ t.integer "application_id", :null => false
19
+ t.string "token", :null => false
20
+ t.integer "expires_in", :null => false
21
+ t.string "redirect_uri", :null => false
22
+ t.datetime "created_at", :null => false
23
+ t.datetime "revoked_at"
24
+ t.string "scopes"
25
+ end
26
+
27
+ add_index "oauth_access_grants", ["token"], :name => "index_oauth_access_grants_on_token", :unique => true
28
+
29
+ create_table "oauth_access_tokens", :force => true do |t|
30
+ t.integer "resource_owner_id"
31
+ t.integer "application_id", :null => false
32
+ t.string "token", :null => false
33
+ t.string "refresh_token"
34
+ t.integer "expires_in"
35
+ t.datetime "revoked_at"
36
+ t.datetime "created_at", :null => false
37
+ t.string "scopes"
38
+ end
39
+
40
+ add_index "oauth_access_tokens", ["refresh_token"], :name => "index_oauth_access_tokens_on_refresh_token", :unique => true
41
+ add_index "oauth_access_tokens", ["resource_owner_id"], :name => "index_oauth_access_tokens_on_resource_owner_id"
42
+ add_index "oauth_access_tokens", ["token"], :name => "index_oauth_access_tokens_on_token", :unique => true
43
+
44
+ create_table "oauth_applications", :force => true do |t|
45
+ t.string "name", :null => false
46
+ t.string "uid", :null => false
47
+ t.string "secret", :null => false
48
+ t.string "redirect_uri", :null => false
49
+ t.datetime "created_at", :null => false
50
+ t.datetime "updated_at", :null => false
51
+ end
52
+
53
+ add_index "oauth_applications", ["uid"], :name => "index_oauth_applications_on_uid", :unique => true
54
+
55
+ create_table "users", :force => true do |t|
56
+ t.string "name"
57
+ t.datetime "created_at", :null => false
58
+ t.datetime "updated_at", :null => false
59
+ t.string "password_digest"
60
+ end
61
+
62
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :access_grant, :class => Doorkeeper::AccessGrant do
3
+ sequence(:resource_owner_id) { |n| n }
4
+ application
5
+ redirect_uri "https://app.com/callback"
6
+ expires_in 100
7
+ scopes "public write"
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :access_token, :class => Doorkeeper::AccessToken do
3
+ sequence(:resource_owner_id) { |n| n }
4
+ application
5
+ expires_in 2.hours
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :application, :class => Doorkeeper::Application do
3
+ sequence(:name){ |n| "Application #{n}" }
4
+ redirect_uri "https://app.com/callback"
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper_integration'
2
+ require 'generators/doorkeeper/install_generator'
3
+
4
+
5
+ describe 'Doorkeeper::InstallGenerator' do
6
+ include GeneratorSpec::TestCase
7
+
8
+ tests Doorkeeper::InstallGenerator
9
+ destination ::File.expand_path("../tmp/dummy", __FILE__)
10
+
11
+ describe "after running the generator" do
12
+ before :each do
13
+ prepare_destination
14
+ FileUtils.mkdir(::File.expand_path("config", Pathname(destination_root)))
15
+ FileUtils.copy_file(::File.expand_path("../templates/routes.rb", __FILE__), ::File.expand_path("config/routes.rb", Pathname.new(destination_root)))
16
+ run_generator
17
+ end
18
+
19
+ it "creates a migration" do
20
+ assert_migration "db/migrate/create_doorkeeper_tables.rb"
21
+ end
22
+
23
+ it "creates an initializer file" do
24
+ assert_file 'config/initializers/doorkeeper.rb'
25
+ end
26
+
27
+ it "copies the locale file" do
28
+ assert_file 'config/locales/doorkeeper.en.yml'
29
+ end
30
+
31
+ it "adds sample route" do
32
+ assert_file "config/routes.rb", /mount Doorkeeper::Engine/
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper_integration'
2
+ require 'generators/doorkeeper/views_generator'
3
+
4
+ describe Doorkeeper::Generators::ViewsGenerator do
5
+ include GeneratorSpec::TestCase
6
+
7
+ tests Doorkeeper::Generators::ViewsGenerator
8
+ destination File.expand_path('../tmp/dummy', __FILE__)
9
+
10
+ before :each do
11
+ prepare_destination
12
+ end
13
+
14
+ it 'create all views' do
15
+ run_generator
16
+ assert_file 'app/views/doorkeeper/applications/_form.html.erb'
17
+ assert_file 'app/views/doorkeeper/applications/edit.html.erb'
18
+ assert_file 'app/views/doorkeeper/applications/index.html.erb'
19
+ assert_file 'app/views/doorkeeper/applications/new.html.erb'
20
+ assert_file 'app/views/doorkeeper/applications/show.html.erb'
21
+
22
+ assert_file 'app/views/doorkeeper/authorizations/error.html.erb'
23
+ assert_file 'app/views/doorkeeper/authorizations/new.html.erb'
24
+
25
+ assert_file 'app/views/doorkeeper/authorized_applications/index.html.erb'
26
+ end
27
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper_integration'
2
+
3
+ describe Doorkeeper, "configuration" do
4
+ subject { Doorkeeper.configuration }
5
+
6
+ describe "resource_owner_authenticator" do
7
+ it "sets the block that is accessible via authenticate_resource_owner" do
8
+ block = proc do end
9
+ Doorkeeper.configure do
10
+ resource_owner_authenticator &block
11
+ end
12
+ subject.authenticate_resource_owner.should == block
13
+ end
14
+ end
15
+
16
+ describe "admin_authenticator" do
17
+ it "sets the block that is accessible via authenticate_admin" do
18
+ block = proc do end
19
+ Doorkeeper.configure do
20
+ admin_authenticator &block
21
+ end
22
+ subject.authenticate_admin.should == block
23
+ end
24
+ end
25
+
26
+ describe "access_token_expires_in" do
27
+ it "has 2 hours by default" do
28
+ subject.access_token_expires_in.should == 2.hours
29
+ end
30
+
31
+ it "can change the value" do
32
+ Doorkeeper.configure do
33
+ access_token_expires_in 4.hours
34
+ end
35
+ subject.access_token_expires_in.should == 4.hours
36
+ end
37
+
38
+ it "can be set to nil" do
39
+ Doorkeeper.configure do
40
+ access_token_expires_in nil
41
+ end
42
+ subject.access_token_expires_in.should be_nil
43
+ end
44
+ end
45
+
46
+ describe "scopes" do
47
+ it "has default scopes" do
48
+ Doorkeeper.configure { default_scopes :public }
49
+ subject.default_scopes.should include(:public)
50
+ end
51
+
52
+ it 'has optional scopes' do
53
+ Doorkeeper.configure { optional_scopes :write, :update }
54
+ subject.optional_scopes.should include(:write, :update)
55
+ end
56
+
57
+ it 'has all scopes' do
58
+ Doorkeeper.configure do
59
+ default_scopes :normal
60
+ optional_scopes :admin
61
+ end
62
+ subject.scopes.should include(:normal, :admin)
63
+ end
64
+ end
65
+
66
+ describe "use_refresh_token" do
67
+ it "is false by default" do
68
+ subject.refresh_token_enabled?.should be_false
69
+ end
70
+
71
+ it "can change the value" do
72
+ Doorkeeper.configure { use_refresh_token }
73
+ subject.refresh_token_enabled?.should be_true
74
+ end
75
+ end
76
+
77
+ describe 'client_credentials' do
78
+ it 'has defaults order' do
79
+ subject.client_credentials_methods.should == [:from_basic, :from_params]
80
+ end
81
+
82
+ it "can change the value" do
83
+ Doorkeeper.configure { client_credentials :from_digest, :from_params }
84
+ subject.client_credentials_methods.should == [:from_digest, :from_params]
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'timecop'
3
+ require 'active_support/time'
4
+ require 'doorkeeper/models/expirable'
5
+
6
+ describe 'Expirable' do
7
+ subject do
8
+ Class.new do
9
+ include Doorkeeper::Models::Expirable
10
+ end.new
11
+ end
12
+
13
+ before do
14
+ subject.stub :created_at => 1.minute.ago
15
+ end
16
+
17
+ describe :expired? do
18
+ it "is not expired if time has not passed" do
19
+ subject.stub :expires_in => 2.minutes
20
+ subject.should_not be_expired
21
+ end
22
+
23
+ it "is expired if time has passed" do
24
+ subject.stub :expires_in => 10.seconds
25
+ subject.should be_expired
26
+ end
27
+
28
+ it "is not expired if expires_in is not set" do
29
+ subject.stub :expires_in => nil
30
+ subject.should_not be_expired
31
+ end
32
+ end
33
+
34
+ describe :time_left do
35
+ it "returns the time in seconds since it was created" do
36
+ Timecop.freeze(Time.now) do
37
+ subject.stub :created_at => Time.now, :expires_in => 10.seconds
38
+ subject.time_left.should == 10.seconds
39
+ end
40
+ end
41
+
42
+ it "returns 0 if token has expired" do
43
+ Timecop.freeze(Time.now + 1.minute) do
44
+ subject.stub :created_at => 1.minutes.ago, :expires_in => 10.seconds
45
+ subject.time_left.should == 0
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'doorkeeper/models/revocable'
4
+
5
+ describe 'Revocable' do
6
+ subject do
7
+ Class.new do
8
+ include Doorkeeper::Models::Revocable
9
+ end.new
10
+ end
11
+
12
+ describe :revoke do
13
+ it "updates :revoked_at attribute with current time" do
14
+ clock = double :now => stub
15
+ subject.should_receive(:update_attribute).with(:revoked_at, clock.now)
16
+ subject.revoke(clock)
17
+ end
18
+ end
19
+
20
+ describe :revoked? do
21
+ it "is revoked if :revoked_at is set" do
22
+ subject.stub :revoked_at => stub
23
+ subject.should be_revoked
24
+ end
25
+
26
+ it "is not revoked if :revoked_at is not set" do
27
+ subject.stub :revoked_at => nil
28
+ subject.should_not be_revoked
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/module/delegation'
3
+ require 'doorkeeper/oauth/scopes'
4
+ require 'doorkeeper/models/scopes'
5
+
6
+ describe 'Doorkeeper::Models::Scopes' do
7
+ subject do
8
+ Class.new(Hash) do
9
+ include Doorkeeper::Models::Scopes
10
+ end.new
11
+ end
12
+
13
+ before do
14
+ subject[:scopes] = 'public admin'
15
+ end
16
+
17
+ describe :scopes do
18
+ it 'is a `Scopes` class' do
19
+ subject.scopes.should be_a(Doorkeeper::OAuth::Scopes)
20
+ end
21
+
22
+ it 'includes scopes' do
23
+ subject.scopes.should include(:public)
24
+ end
25
+ end
26
+
27
+ describe :scopes_string do
28
+ it 'is a `Scopes` class' do
29
+ subject.scopes_string.should == 'public admin'
30
+ end
31
+ end
32
+ end