doorkeeper 0.4.2 → 0.5.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 (118) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +5 -1
  3. data/CHANGELOG.md +29 -0
  4. data/Gemfile +12 -4
  5. data/README.md +76 -7
  6. data/Rakefile +1 -25
  7. data/app/assets/javascripts/doorkeeper/application.js +0 -7
  8. data/app/controllers/doorkeeper/application_controller.rb +1 -27
  9. data/app/controllers/doorkeeper/applications_controller.rb +14 -6
  10. data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
  11. data/app/controllers/doorkeeper/token_info_controller.rb +11 -0
  12. data/app/controllers/doorkeeper/tokens_controller.rb +11 -8
  13. data/app/validators/redirect_uri_validator.rb +12 -0
  14. data/app/views/doorkeeper/applications/_form.html.erb +3 -3
  15. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  16. data/app/views/doorkeeper/applications/index.html.erb +4 -4
  17. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  18. data/app/views/doorkeeper/applications/show.html.erb +3 -3
  19. data/app/views/doorkeeper/authorizations/new.html.erb +2 -2
  20. data/app/views/doorkeeper/authorized_applications/index.html.erb +1 -1
  21. data/config/locales/en.yml +35 -0
  22. data/doorkeeper.gemspec +3 -3
  23. data/gemfiles/gemfile.rails-3.1.x +10 -0
  24. data/gemfiles/gemfile.rails-3.2.x +10 -0
  25. data/lib/doorkeeper.rb +10 -3
  26. data/lib/doorkeeper/config.rb +56 -38
  27. data/lib/doorkeeper/doorkeeper_for.rb +2 -0
  28. data/lib/doorkeeper/engine.rb +3 -32
  29. data/lib/doorkeeper/helpers/controller.rb +29 -0
  30. data/lib/doorkeeper/helpers/filter.rb +4 -18
  31. data/{app/models/doorkeeper → lib/doorkeeper/models}/access_grant.rb +7 -7
  32. data/{app/models/doorkeeper → lib/doorkeeper/models}/access_token.rb +27 -24
  33. data/lib/doorkeeper/models/accessible.rb +9 -0
  34. data/lib/doorkeeper/models/active_record/access_grant.rb +5 -0
  35. data/lib/doorkeeper/models/active_record/access_token.rb +15 -0
  36. data/lib/doorkeeper/models/active_record/application.rb +18 -0
  37. data/lib/doorkeeper/models/application.rb +38 -0
  38. data/lib/doorkeeper/models/expirable.rb +6 -4
  39. data/lib/doorkeeper/models/mongoid/access_grant.rb +22 -0
  40. data/lib/doorkeeper/models/mongoid/access_token.rb +35 -0
  41. data/lib/doorkeeper/models/mongoid/application.rb +22 -0
  42. data/lib/doorkeeper/models/mongoid/revocable.rb +15 -0
  43. data/lib/doorkeeper/models/mongoid/scopes.rb +15 -0
  44. data/lib/doorkeeper/models/ownership.rb +16 -0
  45. data/lib/doorkeeper/models/revocable.rb +1 -1
  46. data/lib/doorkeeper/models/scopes.rb +9 -5
  47. data/lib/doorkeeper/oauth/access_token_request.rb +2 -2
  48. data/lib/doorkeeper/oauth/authorization.rb +1 -0
  49. data/lib/doorkeeper/oauth/authorization/code.rb +5 -3
  50. data/lib/doorkeeper/oauth/client.rb +2 -2
  51. data/lib/doorkeeper/oauth/client_credentials_request.rb +4 -1
  52. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -5
  53. data/lib/doorkeeper/oauth/password_access_token_request.rb +2 -5
  54. data/lib/doorkeeper/oauth/token.rb +36 -0
  55. data/lib/doorkeeper/rails/routes.rb +77 -0
  56. data/lib/doorkeeper/rails/routes/mapper.rb +28 -0
  57. data/lib/doorkeeper/rails/routes/mapping.rb +39 -0
  58. data/lib/doorkeeper/version.rb +1 -1
  59. data/lib/generators/doorkeeper/application_owner_generator.rb +15 -0
  60. data/lib/generators/doorkeeper/install_generator.rb +2 -9
  61. data/lib/generators/doorkeeper/migration_generator.rb +15 -0
  62. data/lib/generators/doorkeeper/templates/README +15 -1
  63. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb +7 -0
  64. data/lib/generators/doorkeeper/templates/initializer.rb +31 -15
  65. data/lib/generators/doorkeeper/templates/migration.rb +7 -4
  66. data/lib/generators/doorkeeper/views_generator.rb +1 -1
  67. data/script/run_all +3 -0
  68. data/spec/controllers/applications_controller_spec.rb +1 -1
  69. data/spec/controllers/authorizations_controller_spec.rb +4 -4
  70. data/spec/controllers/protected_resources_controller_spec.rb +7 -7
  71. data/spec/controllers/token_info_controller_spec.rb +54 -0
  72. data/spec/controllers/tokens_controller_spec.rb +3 -2
  73. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +7 -0
  74. data/spec/dummy/app/models/user.rb +16 -5
  75. data/spec/dummy/config/application.rb +4 -7
  76. data/spec/dummy/config/boot.rb +3 -7
  77. data/spec/dummy/config/initializers/doorkeeper.rb +13 -0
  78. data/spec/dummy/config/mongoid.yml +7 -0
  79. data/spec/dummy/config/routes.rb +29 -1
  80. data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +1 -1
  81. data/spec/dummy/db/migrate/20120524202412_create_doorkeeper_tables.rb +6 -4
  82. data/spec/dummy/db/schema.rb +5 -3
  83. data/spec/generators/application_owner_generator_spec.rb +23 -0
  84. data/spec/generators/install_generator_spec.rb +1 -6
  85. data/spec/generators/migration_generator_spec.rb +20 -0
  86. data/spec/lib/config_spec.rb +72 -4
  87. data/spec/lib/models/expirable_spec.rb +8 -11
  88. data/spec/lib/models/revocable_spec.rb +1 -1
  89. data/spec/lib/oauth/access_token_request_spec.rb +15 -9
  90. data/spec/lib/oauth/authorization_request_spec.rb +1 -0
  91. data/spec/lib/oauth/client_credentials_request_spec.rb +15 -9
  92. data/spec/lib/oauth/client_spec.rb +5 -8
  93. data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -20
  94. data/spec/lib/oauth/password_access_token_request_spec.rb +16 -9
  95. data/spec/lib/oauth/token_spec.rb +83 -0
  96. data/spec/models/doorkeeper/access_token_spec.rb +41 -1
  97. data/spec/models/doorkeeper/application_spec.rb +53 -20
  98. data/spec/requests/flows/authorization_code_spec.rb +1 -1
  99. data/spec/requests/flows/client_credentials_spec.rb +2 -0
  100. data/spec/requests/flows/password_spec.rb +25 -0
  101. data/spec/requests/flows/refresh_token_spec.rb +5 -2
  102. data/spec/requests/protected_resources/private_api_spec.rb +10 -3
  103. data/spec/routing/custom_controller_routes_spec.rb +44 -0
  104. data/spec/routing/default_routes_spec.rb +32 -0
  105. data/spec/spec_helper.rb +1 -0
  106. data/spec/spec_helper_integration.rb +18 -8
  107. data/spec/support/dependencies/factory_girl.rb +0 -3
  108. data/spec/support/orm/active_record.rb +11 -0
  109. data/spec/support/orm/mongoid.rb +26 -0
  110. data/spec/support/shared/controllers_shared_context.rb +2 -2
  111. data/spec/support/shared/models_shared_examples.rb +16 -0
  112. data/spec/validators/redirect_uri_validator_spec.rb +40 -0
  113. metadata +61 -37
  114. data/app/helpers/doorkeeper/application_helper.rb +0 -4
  115. data/app/models/doorkeeper/application.rb +0 -54
  116. data/config/routes.rb +0 -9
  117. data/lib/tasks/doorkeeper_tasks.rake +0 -4
  118. data/spec/support/dependencies/database_cleaner.rb +0 -16
data/.gitignore CHANGED
@@ -10,3 +10,5 @@ Gemfile.lock
10
10
  gemfiles/*.lock
11
11
  spec/generators/tmp
12
12
  .rvmrc
13
+ *.swp
14
+
data/.travis.yml CHANGED
@@ -2,7 +2,11 @@ rvm:
2
2
  - 1.9.3
3
3
  - 1.8.7
4
4
  - 1.9.2
5
- - rbx
5
+ env:
6
+ - DOORKEEPER_ORM=active_record
7
+ - DOORKEEPER_ORM=mongoid
6
8
  gemfile:
7
9
  - gemfiles/gemfile.rails-3.1.x
8
10
  - gemfiles/gemfile.rails-3.2.x
11
+ services:
12
+ - mongodb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0.rc1
4
+
5
+ Official support for rubinius was removed.
6
+
7
+ - enhancements
8
+ - Configure the way access token is retrieved from request (default to bearer header)
9
+ - Authorization Code expiration time is now configurable
10
+ - Add support for mongoid
11
+ - [#78, #128, #137, #138] Application Ownership
12
+ - [#92] Allow users to skip controllers
13
+ - [#99] Remove deprecated warnings for data-* attributes [@towerhe](https://github.com/towerhe)
14
+ - [#101] Return existing access_token for PasswordAccessTokenRequest [@benoist](https://github.com/benoist)
15
+ - [#104] Changed access token scopes example code to default_scopes and optional_scopes [@amkirwan](https://github.com/amkirwan)
16
+ - [#107] Fix typos in initializer
17
+ - [#123] i18n for validator, flash messages [@petergoldstein](https://github.com/petergoldstein)
18
+ - [#140] ActiveRecord is the default value for the ORM [@petergoldstein](https://github.com/petergoldstein)
19
+ - internals
20
+ - [#112, #120] Replacing update_attribute with update_column to eliminate deprecation warnings [@rmoriz](https://github.com/rmoriz), [@petergoldstein](https://github.com/petergoldstein)
21
+ - [#121] Updating all development dependencies to recent versions. [@petergoldstein](https://github.com/petergoldstein)
22
+ - [#144] Adding MongoDB dependency to .travis.yml [@petergoldstein](https://github.com/petergoldstein)
23
+ - [#143] Displays errors for unconfigured error messages [@timgaleckas](https://github.com/timgaleckas)
24
+ - bugfixes
25
+ - [#102] Not returning 401 when access token generation fails [@cslew](https://github.com/cslew)
26
+ - [#125] Doorkeeper is using ActiveRecord version of as_json in ORM agnostic code [@petergoldstein](https://github.com/petergoldstein)
27
+ - [#142] Prevent double submission of password based authentication [@bdurand](https://github.com/bdurand)
28
+ - documentation
29
+ - [#141] Add rack-cors middleware to readme [@gottfrois](https://github.com/gottfrois)
30
+
3
31
  ## 0.4.2
4
32
 
5
33
  - bugfixes:
@@ -19,6 +47,7 @@
19
47
  - enhancements
20
48
  - [#83] Add Resource Owner Password Credentials flow [@jaimeiniesta](https://github.com/jaimeiniesta)
21
49
  - [#76] Allow token expiration to be disabled [@mattgreen](https://github.com/mattgreen)
50
+ - [#89] Configure the way client credentials are retrieved from request
22
51
  - [#b6470a] Add Client Credentials flow
23
52
  - internals
24
53
  - [#2ece8d, #f93778] Introduce Client and ErrorResponse classes
data/Gemfile CHANGED
@@ -1,6 +1,14 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- gemspec
3
+ gem 'jquery-rails'
4
+
5
+ group :mongoid do
6
+ gem 'mongoid', '~> 2.4'
7
+ gem 'bson_ext', '~> 1.6.0'
8
+ end
4
9
 
5
- # jquery-rails is used by the dummy application
6
- gem "jquery-rails"
10
+ group :active_record do
11
+ gem 'activerecord', '~> 3.1'
12
+ end
13
+
14
+ gemspec
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/applicake/doorkeeper.png)](http://travis-ci.org/applicake/doorkeeper)
4
4
  [![Dependency Status](https://gemnasium.com/applicake/doorkeeper.png)](https://gemnasium.com/applicake/doorkeeper)
5
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/applicake/doorkeeper)
5
6
 
6
7
  Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider functionality to your application.
7
8
 
@@ -9,29 +10,67 @@ The gem is under constant development. It is based in the [version 22 of the OAu
9
10
 
10
11
  For more information about the supported features, check out the related [page in the wiki](https://github.com/applicake/doorkeeper/wiki/Supported-Features). For more information about OAuth 2 go to [OAuth 2 Specs (Draft)](http://tools.ietf.org/html/draft-ietf-oauth-v2-22).
11
12
 
13
+ ## Requirements
14
+
15
+ ### Ruby
16
+
17
+ - 1.8.7, 1.9.2 or 1.9.3
18
+
19
+ ### Rails
20
+
21
+ - 3.1.x or 3.2.x
22
+
23
+ ### ORM
24
+
25
+ - ActiveRecord
26
+ - Mongoid 2 (only for doorkeeper v0.5+)
27
+
12
28
  ## Installation
13
29
 
14
30
  Put this in your Gemfile:
15
31
 
16
32
  ``` ruby
17
- gem 'doorkeeper', '~> 0.4.0'
33
+ gem 'doorkeeper', '~> 0.5.0.rc1'
18
34
  ```
19
35
 
20
36
  Run the installation generator with:
21
37
 
22
38
  rails generate doorkeeper:install
23
39
 
24
- This will generate the doorkeeper initializer and the OAuth tables migration. Don't forget to run the migration in your application:
40
+ This will install the doorkeeper initializer into `config/initializers/doorkeeper.rb`.
41
+
42
+ ## Configuration
43
+
44
+ ### Active Record
45
+
46
+ By default doorkeeper is configured to use active record, so to start you have to generate the migration tables:
47
+
48
+ rails generate doorkeeper:migration
49
+
50
+ Don't forget to run the migration with:
25
51
 
26
52
  rake db:migrate
27
53
 
28
- ## Configuration
54
+ ### Mongoid (only doorkeeper v0.5+)
55
+
56
+ Doorkeeper currently supports Mongoid 2. To start using it, you have to set the `orm` configuration:
57
+
58
+ ``` ruby
59
+ Doorkeeper.configure do
60
+ orm :mongoid
61
+ end
62
+ ```
63
+
64
+ **Note:** Make sure you create indexes for doorkeeper models. You can do this either by running `db:mongoid:create_indexes`
65
+ or by adding `autocreate_indexes: true` to your `config/mongoid.yml`
66
+
67
+ ### Routes
29
68
 
30
- The installation script will automatically add the Doorkeeper routes into your app, like this:
69
+ The installation script will also automatically add the Doorkeeper routes into your app, like this:
31
70
 
32
71
  ``` ruby
33
72
  Rails.application.routes.draw do
34
- mount Doorkeeper::Engine => "/oauth"
73
+ use_doorkeeper
35
74
  # your routes
36
75
  end
37
76
  ```
@@ -44,6 +83,10 @@ This will mount following routes:
44
83
  POST /oauth/token
45
84
  resources /oauth/applications
46
85
 
86
+ For more information on how to customize routes, check out [this page on the wiki](https://github.com/applicake/doorkeeper/wiki/Customizing-routes).
87
+
88
+ ### Authenticating
89
+
47
90
  You need to configure Doorkeeper in order to provide resource_owner model and authentication block `initializers/doorkeeper.rb`
48
91
 
49
92
  ``` ruby
@@ -92,6 +135,22 @@ class Api::V1::ProductsController < Api::V1::ApiController
92
135
  end
93
136
  ```
94
137
 
138
+ ### ActionController::Metal integration and other integrations
139
+
140
+ The `doorkeeper_for` filter is intended to work with ActionController::Metal too. You only need to include the required `ActionController` modules:
141
+
142
+ ```ruby
143
+ class MetalController < ActionController::Metal
144
+ include AbstractController::Callbacks
145
+ include ActionController::Head
146
+ include Doorkeeper::Helpers::Filter
147
+
148
+ doorkeeper_for :all
149
+ end
150
+ ```
151
+
152
+ For more information about integration and other integrations, check out [the related wiki page](https://github.com/applicake/doorkeeper/wiki/ActionController::Metal-with-doorkeeper).
153
+
95
154
  ### Access Token Scopes
96
155
 
97
156
  You can also require the access token to have specific scopes in certain actions:
@@ -100,8 +159,8 @@ First configure the scopes in `initializers/doorkeeper.rb`
100
159
 
101
160
  ```ruby
102
161
  Doorkeeper.configure do
103
- default_scope :public # if no scope was requested, this will be the default
104
- optional_scope :admin, :write
162
+ default_scopes :public # if no scope was requested, this will be the default
163
+ optional_scopes :admin, :write
105
164
  end
106
165
  ```
107
166
 
@@ -175,6 +234,16 @@ All supported ruby versions are [listed here](https://github.com/applicake/doork
175
234
 
176
235
  ## Additional information
177
236
 
237
+ ### Cross Origin Resource Sharing
238
+
239
+ You might want to use Doorkeeper to protect an API and want an other application running in a different context (like a mobile application) to request on your API.
240
+
241
+ For mobile application, you might have to setup Cross Origin Resource Sharing. More info [here](http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/)
242
+
243
+ In order to setup the bahavior, you can take a look at [rack-cors](https://github.com/cyu/rack-cors). It's a rack middleware that will set http headers for you in order to be able to make cross domain requests to your doorkeeper protected application (usualy your API).
244
+
245
+ [Here](https://github.com/gottfrois/doorkeeper-provider-app) is a demo application where rack-cors has been setup.
246
+
178
247
  ### Maintainers
179
248
 
180
249
  - Felipe Elias Philipp ([github.com/felipeelias](https://github.com/felipeelias), [twitter.com/felipeelias](https://twitter.com/felipeelias))
data/Rakefile CHANGED
@@ -1,25 +1,4 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- begin
8
- require 'rdoc/task'
9
- rescue LoadError
10
- require 'rdoc/rdoc'
11
- require 'rake/rdoctask'
12
- RDoc::Task = Rake::RDocTask
13
- end
14
-
15
- RDoc::Task.new(:rdoc) do |rdoc|
16
- rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'Doorkeeper'
18
- rdoc.options << '--line-numbers'
19
- rdoc.rdoc_files.include('README.rdoc')
20
- rdoc.rdoc_files.include('lib/**/*.rb')
21
- end
22
-
1
+ require 'bundler/setup'
23
2
  require 'rspec/core/rake_task'
24
3
 
25
4
  desc 'Default: run specs.'
@@ -36,7 +15,4 @@ namespace :doorkeeper do
36
15
  end
37
16
  end
38
17
 
39
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
40
- load 'rails/tasks/engine.rake'
41
-
42
18
  Bundler::GemHelper.install_tasks
@@ -1,9 +1,2 @@
1
- // This is a manifest file that'll be compiled into including all the files listed below.
2
- // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
- // be included in the compiled file accessible from http://example.com/assets/application.js
4
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
- // the compiled file.
6
- //
7
1
  //= require jquery
8
2
  //= require jquery_ujs
9
- //= require_tree .
@@ -1,31 +1,5 @@
1
1
  module Doorkeeper
2
2
  class ApplicationController < ActionController::Base
3
- private
4
-
5
- def authenticate_resource_owner!
6
- current_resource_owner
7
- end
8
-
9
- def current_resource_owner
10
- instance_exec(main_app, &Doorkeeper.configuration.authenticate_resource_owner)
11
- end
12
-
13
- def resource_owner_from_credentials
14
- instance_exec(main_app, &Doorkeeper.configuration.resource_owner_from_credentials)
15
- end
16
-
17
- def authenticate_admin!
18
- if block = Doorkeeper.configuration.authenticate_admin
19
- instance_exec(main_app, &block)
20
- end
21
- end
22
-
23
- def method_missing(method, *args, &block)
24
- if method =~ /_(url|path)$/
25
- raise "Your path has not been found. Didn't you mean to call routes.#{method} in doorkeeper configuration blocks?"
26
- else
27
- super
28
- end
29
- end
3
+ include Doorkeeper::Helpers::Controller
30
4
  end
31
5
  end
@@ -14,8 +14,12 @@ module Doorkeeper
14
14
 
15
15
  def create
16
16
  @application = Application.new(params[:application])
17
- flash[:notice] = "Application created" if @application.save
18
- respond_with @application
17
+ if @application.save
18
+ flash[:notice] = I18n.t(:notice, :scope => [:doorkeeper, :flash, :applications, :create])
19
+ respond_with [:oauth, @application]
20
+ else
21
+ render :new
22
+ end
19
23
  end
20
24
 
21
25
  def show
@@ -28,14 +32,18 @@ module Doorkeeper
28
32
 
29
33
  def update
30
34
  @application = Application.find(params[:id])
31
- flash[:notice] = "Application updated" if @application.update_attributes(params[:application])
32
- respond_with @application
35
+ if @application.update_attributes(params[:application])
36
+ flash[:notice] = I18n.t(:notice, :scope => [:doorkeeper, :flash, :applications, :update])
37
+ respond_with [:oauth, @application]
38
+ else
39
+ render :edit
40
+ end
33
41
  end
34
42
 
35
43
  def destroy
36
44
  @application = Application.find(params[:id])
37
- flash[:notice] = "Application deleted" if @application.destroy
38
- redirect_to applications_url
45
+ flash[:notice] = I18n.t(:notice, :scope => [:doorkeeper, :flash, :applications, :destroy]) if @application.destroy
46
+ redirect_to oauth_applications_url
39
47
  end
40
48
  end
41
49
  end
@@ -7,6 +7,6 @@ class Doorkeeper::AuthorizedApplicationsController < Doorkeeper::ApplicationCont
7
7
 
8
8
  def destroy
9
9
  Doorkeeper::AccessToken.revoke_all_for params[:id], current_resource_owner
10
- redirect_to authorized_applications_url, :notice => "Application revoked."
10
+ redirect_to oauth_authorized_applications_url, :notice => "Application revoked."
11
11
  end
12
12
  end
@@ -0,0 +1,11 @@
1
+ class Doorkeeper::TokenInfoController < Doorkeeper::ApplicationController
2
+
3
+ def show
4
+ if doorkeeper_token && doorkeeper_token.accessible?
5
+ render :json => doorkeeper_token, :status => :ok
6
+ else
7
+ render :json => Doorkeeper::OAuth::ErrorResponse.new(:name => :invalid_request), :status => :unauthorized
8
+ end
9
+ end
10
+
11
+ end
@@ -23,14 +23,17 @@ class Doorkeeper::TokensController < Doorkeeper::ApplicationController
23
23
  end
24
24
 
25
25
  def token
26
- case params[:grant_type]
27
- when 'password'
28
- owner = resource_owner_from_credentials
29
- @token ||= Doorkeeper::OAuth::PasswordAccessTokenRequest.new(client, owner, params)
30
- when 'client_credentials'
31
- @token ||= Doorkeeper::OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, params)
32
- else
33
- @token ||= Doorkeeper::OAuth::AccessTokenRequest.new(client, params)
26
+ unless defined?(@token) && @token
27
+ case params[:grant_type]
28
+ when 'password'
29
+ owner = resource_owner_from_credentials
30
+ @token = Doorkeeper::OAuth::PasswordAccessTokenRequest.new(client, owner, params)
31
+ when 'client_credentials'
32
+ @token = Doorkeeper::OAuth::ClientCredentialsRequest.new(Doorkeeper.configuration, client, params)
33
+ else
34
+ @token = Doorkeeper::OAuth::AccessTokenRequest.new(client, params)
35
+ end
34
36
  end
37
+ @token
35
38
  end
36
39
  end
@@ -0,0 +1,12 @@
1
+ require 'uri'
2
+
3
+ class RedirectUriValidator < ActiveModel::EachValidator
4
+ def validate_each(record, attribute, value)
5
+ uri = ::URI.parse(value)
6
+ record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
7
+ record.errors.add(attribute, :relative_uri) if uri.scheme.nil? || uri.host.nil?
8
+ record.errors.add(attribute, :has_query_parameter) unless uri.query.nil?
9
+ rescue URI::InvalidURIError => e
10
+ record.errors.add(attribute, :invalid_uri)
11
+ end
12
+ end
@@ -1,6 +1,6 @@
1
- <%= form_for(application) do |f| %>
1
+ <%= form_for([:oauth, application]) do |f| %>
2
2
  <fieldset>
3
- <% if @application.errors.any? %>
3
+ <% if application.errors.any? %>
4
4
  <div class="alert-message error" data-alert><a class="close" href="#">×</a><p>Whoops! Check your form for possible errors</p></div>
5
5
  <% end %>
6
6
 
@@ -20,7 +20,7 @@
20
20
 
21
21
  <div class="actions">
22
22
  <%= f.submit :Submit, :class => "btn primary" %>
23
- <%= link_to "Cancel", applications_path, :class => "btn" %>
23
+ <%= link_to "Cancel", oauth_applications_path, :class => "btn" %>
24
24
  </div>
25
25
  </fieldset>
26
26
  <% end %>
@@ -8,6 +8,6 @@
8
8
 
9
9
  <div class="span6">
10
10
  <h3>Actions</h3>
11
- <p><%= link_to 'Back to application list', applications_path %></p>
11
+ <p><%= link_to 'Back to application list', oauth_applications_path %></p>
12
12
  </div>
13
13
 
@@ -3,7 +3,7 @@
3
3
  <h2>Your applications</h2>
4
4
  </header>
5
5
 
6
- <p><%= link_to 'New Application', new_application_path %></p>
6
+ <p><%= link_to 'New Application', new_oauth_application_path %></p>
7
7
 
8
8
  <table class="zebra-striped">
9
9
  <thead>
@@ -17,10 +17,10 @@
17
17
  <tbody>
18
18
  <% @applications.each do |application| %>
19
19
  <tr id="application_<%= application.id %>">
20
- <td><%= link_to application.name, application %></td>
20
+ <td><%= link_to application.name, [:oauth, application] %></td>
21
21
  <td><%= application.redirect_uri %></td>
22
- <td><%= link_to 'Edit', edit_application_path(application) %></td>
23
- <td><%= link_to 'Destroy', application, :confirm => 'Are you sure?', :method => :delete %></td>
22
+ <td><%= link_to 'Edit', edit_oauth_application_path(application) %></td>
23
+ <td><%= link_to 'Destroy', [:oauth, application], :data => { :confirm => 'Are you sure?' }, :method => :delete %></td>
24
24
  </tr>
25
25
  <% end %>
26
26
  </tbody>