doorkeeper 2.1.4 → 3.1.0
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.
- checksums.yaml +4 -4
- data/.hound.yml +4 -0
- data/.travis.yml +5 -24
- data/CONTRIBUTING.md +23 -13
- data/Gemfile +3 -7
- data/{CHANGELOG.md → NEWS.md} +137 -42
- data/README.md +60 -46
- data/RELEASING.md +5 -3
- data/app/assets/stylesheets/doorkeeper/admin/application.css +1 -5
- data/app/controllers/doorkeeper/applications_controller.rb +2 -2
- data/app/helpers/doorkeeper/dashboard_helper.rb +1 -1
- data/app/validators/redirect_uri_validator.rb +1 -1
- data/app/views/doorkeeper/applications/_form.html.erb +13 -2
- data/app/views/doorkeeper/applications/show.html.erb +3 -2
- data/app/views/doorkeeper/authorizations/new.html.erb +1 -1
- data/app/views/layouts/doorkeeper/admin.html.erb +5 -2
- data/config/locales/en.yml +4 -32
- data/doorkeeper.gemspec +4 -8
- data/lib/doorkeeper/config.rb +20 -29
- data/lib/doorkeeper/engine.rb +7 -1
- data/lib/doorkeeper/errors.rb +12 -0
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +6 -0
- data/lib/doorkeeper/models/access_grant_mixin.rb +3 -2
- data/lib/doorkeeper/models/access_token_mixin.rb +12 -4
- data/lib/doorkeeper/models/application_mixin.rb +11 -18
- data/lib/doorkeeper/models/concerns/revocable.rb +2 -2
- data/lib/doorkeeper/oauth/authorization/token.rb +15 -6
- data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -5
- data/lib/doorkeeper/oauth/client.rb +9 -8
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +3 -4
- data/lib/doorkeeper/oauth/error.rb +5 -1
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -1
- data/lib/doorkeeper/oauth/refresh_token_request.rb +17 -7
- data/lib/doorkeeper/orm/active_record/access_grant.rb +2 -2
- data/lib/doorkeeper/orm/active_record/access_token.rb +2 -2
- data/lib/doorkeeper/orm/active_record/application.rb +2 -2
- data/lib/doorkeeper/orm/active_record.rb +22 -0
- data/lib/doorkeeper/rails/helpers.rb +19 -29
- data/lib/doorkeeper/request/authorization_code.rb +10 -15
- data/lib/doorkeeper/request/client_credentials.rb +9 -15
- data/lib/doorkeeper/request/code.rb +7 -13
- data/lib/doorkeeper/request/password.rb +10 -15
- data/lib/doorkeeper/request/refresh_token.rb +11 -13
- data/lib/doorkeeper/request/strategy.rb +17 -0
- data/lib/doorkeeper/request/token.rb +7 -13
- data/lib/doorkeeper/request.rb +18 -8
- data/lib/doorkeeper/server.rb +2 -2
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +0 -4
- data/lib/generators/doorkeeper/templates/README +0 -20
- data/lib/generators/doorkeeper/templates/initializer.rb +5 -3
- data/lib/generators/doorkeeper/templates/migration.rb +8 -0
- data/spec/controllers/applications_controller_spec.rb +0 -1
- data/spec/controllers/protected_resources_controller_spec.rb +115 -14
- data/spec/controllers/token_info_controller_spec.rb +0 -4
- data/spec/controllers/tokens_controller_spec.rb +34 -3
- data/spec/dummy/app/models/user.rb +2 -24
- data/spec/dummy/config/application.rb +2 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -2
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +24 -0
- data/spec/lib/config_spec.rb +20 -4
- data/spec/lib/models/revocable_spec.rb +2 -2
- data/spec/lib/oauth/authorization_code_request_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +2 -2
- data/spec/lib/oauth/client_credentials/creator_spec.rb +25 -1
- data/spec/lib/oauth/error_response_spec.rb +7 -7
- data/spec/lib/oauth/error_spec.rb +9 -5
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +3 -3
- data/spec/lib/oauth/password_access_token_request_spec.rb +1 -1
- data/spec/lib/oauth/pre_authorization_spec.rb +9 -10
- data/spec/lib/oauth/refresh_token_request_spec.rb +26 -6
- data/spec/lib/oauth/scopes_spec.rb +1 -1
- data/spec/lib/oauth/token_request_spec.rb +6 -3
- data/spec/lib/request/strategy_spec.rb +53 -0
- data/spec/lib/server_spec.rb +4 -2
- data/spec/models/doorkeeper/access_grant_spec.rb +5 -5
- data/spec/models/doorkeeper/access_token_spec.rb +102 -5
- data/spec/models/doorkeeper/application_spec.rb +13 -16
- data/spec/requests/applications/applications_request_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +2 -1
- data/spec/requests/endpoints/token_spec.rb +9 -9
- data/spec/requests/flows/authorization_code_errors_spec.rb +4 -4
- data/spec/requests/flows/authorization_code_spec.rb +36 -2
- data/spec/requests/flows/implicit_grant_spec.rb +14 -5
- data/spec/requests/flows/password_spec.rb +14 -20
- data/spec/requests/flows/refresh_token_spec.rb +15 -7
- data/spec/requests/flows/revoke_token_spec.rb +9 -31
- data/spec/requests/protected_resources/metal_spec.rb +3 -3
- data/spec/requests/protected_resources/private_api_spec.rb +11 -0
- data/spec/routing/custom_controller_routes_spec.rb +1 -2
- data/spec/routing/default_routes_spec.rb +1 -2
- data/spec/routing/scoped_routes_spec.rb +0 -1
- data/spec/spec_helper_integration.rb +10 -7
- data/spec/support/helpers/access_token_request_helper.rb +1 -1
- data/spec/support/helpers/authorization_request_helper.rb +1 -1
- data/spec/support/helpers/config_helper.rb +1 -1
- data/spec/support/helpers/model_helper.rb +1 -1
- data/spec/support/helpers/request_spec_helper.rb +1 -1
- data/spec/support/helpers/url_helper.rb +1 -1
- data/spec/support/shared/models_shared_examples.rb +1 -1
- data/spec/validators/redirect_uri_validator_spec.rb +5 -0
- metadata +127 -98
- data/gemfiles/Gemfile.common.rb +0 -14
- data/gemfiles/Gemfile.mongo_mapper.rb +0 -5
- data/gemfiles/Gemfile.mongoid2.rb +0 -5
- data/gemfiles/Gemfile.mongoid3.rb +0 -4
- data/gemfiles/Gemfile.mongoid4.rb +0 -5
- data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb +0 -12
- data/lib/doorkeeper/generators/doorkeeper/mongo_mapper/templates/indexes.rb +0 -3
- data/lib/doorkeeper/orm/mongo_mapper/access_grant.rb +0 -24
- data/lib/doorkeeper/orm/mongo_mapper/access_token.rb +0 -43
- data/lib/doorkeeper/orm/mongo_mapper/application.rb +0 -29
- data/lib/doorkeeper/orm/mongo_mapper.rb +0 -11
- data/lib/doorkeeper/orm/mongoid2/access_grant.rb +0 -22
- data/lib/doorkeeper/orm/mongoid2/access_token.rb +0 -37
- data/lib/doorkeeper/orm/mongoid2/application.rb +0 -25
- data/lib/doorkeeper/orm/mongoid2/concerns/scopes.rb +0 -30
- data/lib/doorkeeper/orm/mongoid2.rb +0 -11
- data/lib/doorkeeper/orm/mongoid3/access_grant.rb +0 -22
- data/lib/doorkeeper/orm/mongoid3/access_token.rb +0 -37
- data/lib/doorkeeper/orm/mongoid3/application.rb +0 -25
- data/lib/doorkeeper/orm/mongoid3/concerns/scopes.rb +0 -30
- data/lib/doorkeeper/orm/mongoid3.rb +0 -11
- data/lib/doorkeeper/orm/mongoid4/access_grant.rb +0 -22
- data/lib/doorkeeper/orm/mongoid4/access_token.rb +0 -37
- data/lib/doorkeeper/orm/mongoid4/application.rb +0 -25
- data/lib/doorkeeper/orm/mongoid4/concerns/scopes.rb +0 -17
- data/lib/doorkeeper/orm/mongoid4.rb +0 -11
- data/spec/dummy/config/mongo.yml +0 -11
- data/spec/dummy/config/mongoid2.yml +0 -9
- data/spec/dummy/config/mongoid3.yml +0 -18
- data/spec/dummy/config/mongoid4.yml +0 -19
- data/spec/support/orm/mongo_mapper.rb +0 -10
- data/spec/support/orm/mongoid.rb +0 -10
data/README.md
CHANGED
@@ -14,24 +14,25 @@ functionality to your Rails or Grape application.
|
|
14
14
|
## Documentation valid for `master` branch
|
15
15
|
|
16
16
|
Please check the documentation for the version of doorkeeper you are using in:
|
17
|
-
https://github.com/doorkeeper-gem/doorkeeper/releases
|
17
|
+
https://github.com/doorkeeper-gem/doorkeeper/releases
|
18
18
|
|
19
19
|
## Table of Contents
|
20
20
|
|
21
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
22
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
21
23
|
- [Useful links](#useful-links)
|
22
|
-
- [Requirements](#requirements)
|
23
24
|
- [Installation](#installation)
|
24
25
|
- [Configuration](#configuration)
|
25
26
|
- [Active Record](#active-record)
|
26
|
-
- [
|
27
|
-
- [Mongoid indexes](#mongoid-indexes)
|
28
|
-
- [MongoMapper indexes](#mongomapper-indexes)
|
27
|
+
- [Other ORMs](#other-orms)
|
29
28
|
- [Routes](#routes)
|
30
29
|
- [Authenticating](#authenticating)
|
30
|
+
- [Internationalization (I18n)](#internationalization-i18n)
|
31
31
|
- [Protecting resources with OAuth (a.k.a your API endpoint)](#protecting-resources-with-oauth-aka-your-api-endpoint)
|
32
32
|
- [Protect your API with OAuth when using Grape](#protect-your-api-with-oauth-when-using-grape)
|
33
33
|
- [Route Constraints and other integrations](#route-constraints-and-other-integrations)
|
34
34
|
- [Access Token Scopes](#access-token-scopes)
|
35
|
+
- [Custom Access Token Generator](#custom-access-token-generator)
|
35
36
|
- [Authenticated resource owner](#authenticated-resource-owner)
|
36
37
|
- [Applications list](#applications-list)
|
37
38
|
- [Other customizations](#other-customizations)
|
@@ -40,23 +41,19 @@ https://github.com/doorkeeper-gem/doorkeeper/releases.
|
|
40
41
|
- [Contributing](#contributing)
|
41
42
|
- [Other resources](#other-resources)
|
42
43
|
- [Wiki](#wiki)
|
43
|
-
- [Live demo](#live-demo)
|
44
44
|
- [Screencast](#screencast)
|
45
45
|
- [Client applications](#client-applications)
|
46
46
|
- [Contributors](#contributors)
|
47
|
+
- [IETF Standards](#ietf-standards)
|
47
48
|
- [License](#license)
|
49
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
50
|
+
|
48
51
|
|
49
52
|
## Useful links
|
50
53
|
|
51
54
|
- For documentation, please check out our [wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki)
|
52
55
|
- For general questions, please post it in [stack overflow](http://stackoverflow.com/questions/tagged/doorkeeper)
|
53
56
|
|
54
|
-
## Requirements
|
55
|
-
|
56
|
-
- Ruby >= 2.0.0
|
57
|
-
- Rails >= 3.2
|
58
|
-
- ORM ActiveRecord, Mongoid, MongoMapper
|
59
|
-
|
60
57
|
## Installation
|
61
58
|
|
62
59
|
Put this in your Gemfile:
|
@@ -84,29 +81,12 @@ Don't forget to run the migration with:
|
|
84
81
|
|
85
82
|
rake db:migrate
|
86
83
|
|
87
|
-
###
|
88
|
-
|
89
|
-
Doorkeeper currently supports MongoMapper, Mongoid 2 and 3. To start using it,
|
90
|
-
you have to set the `orm` configuration:
|
91
|
-
|
92
|
-
``` ruby
|
93
|
-
Doorkeeper.configure do
|
94
|
-
orm :mongoid2 # or :mongoid3, :mongoid4, :mongo_mapper
|
95
|
-
end
|
96
|
-
```
|
97
|
-
|
98
|
-
#### Mongoid indexes
|
84
|
+
### Other ORMs
|
99
85
|
|
100
|
-
|
101
|
-
|
102
|
-
adding `autocreate_indexes: true` to your `config/mongoid.yml`
|
86
|
+
See [doorkeeper-mongodb project] for mongoid and mongomapper support. Follow along
|
87
|
+
the implementation in that repository to extend doorkeeper with other ORMs.
|
103
88
|
|
104
|
-
|
105
|
-
|
106
|
-
Generate the `db/indexes.rb` file and create indexes for the doorkeeper models:
|
107
|
-
|
108
|
-
rails generate doorkeeper:mongo_mapper:indexes
|
109
|
-
rake db:index
|
89
|
+
[doorkeeper-mongodb project]: https://github.com/doorkeeper-gem/doorkeeper-mongodb
|
110
90
|
|
111
91
|
### Routes
|
112
92
|
|
@@ -125,7 +105,6 @@ This will mount following routes:
|
|
125
105
|
GET /oauth/authorize/:code
|
126
106
|
GET /oauth/authorize
|
127
107
|
POST /oauth/authorize
|
128
|
-
PUT /oauth/authorize
|
129
108
|
DELETE /oauth/authorize
|
130
109
|
POST /oauth/token
|
131
110
|
POST /oauth/revoke
|
@@ -158,6 +137,12 @@ the methods defined over there.
|
|
158
137
|
You may want to check other ways of authentication
|
159
138
|
[here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Authenticating-using-Clearance-or-DIY).
|
160
139
|
|
140
|
+
|
141
|
+
### Internationalization (I18n)
|
142
|
+
|
143
|
+
See language files in [the I18n repository](https://github.com/doorkeeper-gem/doorkeeper-i18n).
|
144
|
+
|
145
|
+
|
161
146
|
## Protecting resources with OAuth (a.k.a your API endpoint)
|
162
147
|
|
163
148
|
To protect your API with OAuth, you just need to setup `before_action`s
|
@@ -253,9 +238,42 @@ class Api::V1::ProductsController < Api::V1::ApiController
|
|
253
238
|
end
|
254
239
|
```
|
255
240
|
|
256
|
-
|
257
|
-
|
258
|
-
|
241
|
+
Please note that there is a logical OR between multiple required scopes. In
|
242
|
+
above example, `doorkeeper_authorize! :admin, :write` means that the access
|
243
|
+
token is required to have either `:admin` scope or `:write` scope, but not need
|
244
|
+
have both of them.
|
245
|
+
|
246
|
+
If want to require the access token to have multiple scopes at the same time,
|
247
|
+
use multiple `doorkeeper_authorize!`, for example:
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
class Api::V1::ProductsController < Api::V1::ApiController
|
251
|
+
before_action -> { doorkeeper_authorize! :public }, only: :index
|
252
|
+
before_action only: [:create, :update, :destroy] do
|
253
|
+
doorkeeper_authorize! :admin
|
254
|
+
doorkeeper_authorize! :write
|
255
|
+
end
|
256
|
+
end
|
257
|
+
```
|
258
|
+
|
259
|
+
In above example, a client can call `:create` action only if its access token
|
260
|
+
have both `:admin` and `:write` scopes.
|
261
|
+
|
262
|
+
### Custom Access Token Generator
|
263
|
+
|
264
|
+
By default a 128 bit access token will be generated. If you require a custom
|
265
|
+
token, such as [JWT](http://jwt.io), specify an object that responds to
|
266
|
+
`.generate(options = {})` and returns a string to be used as the token.
|
267
|
+
|
268
|
+
```ruby
|
269
|
+
Doorkeeper.configure do
|
270
|
+
access_token_generator "Doorkeeper::JWT"
|
271
|
+
end
|
272
|
+
```
|
273
|
+
|
274
|
+
JWT token support is available with
|
275
|
+
[Doorkeeper-JWT](https://github.com/chriswarren/doorkeeper-jwt).
|
276
|
+
|
259
277
|
|
260
278
|
### Authenticated resource owner
|
261
279
|
|
@@ -315,7 +333,9 @@ wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Customizing-routes).
|
|
315
333
|
If you want to upgrade doorkeeper to a new version, check out the [upgrading
|
316
334
|
notes](https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions)
|
317
335
|
and take a look at the
|
318
|
-
[changelog](https://github.com/doorkeeper-gem/doorkeeper/blob/master/
|
336
|
+
[changelog](https://github.com/doorkeeper-gem/doorkeeper/blob/master/NEWS.md).
|
337
|
+
|
338
|
+
Doorkeeper follows [semantic versioning](http://semver.org/).
|
319
339
|
|
320
340
|
## Development
|
321
341
|
|
@@ -353,12 +373,6 @@ page](https://github.com/doorkeeper-gem/doorkeeper/wiki/Contributing).
|
|
353
373
|
You can find everything about doorkeeper in our [wiki
|
354
374
|
here](https://github.com/doorkeeper-gem/doorkeeper/wiki).
|
355
375
|
|
356
|
-
### Live demo
|
357
|
-
|
358
|
-
Check out this [live demo](http://doorkeeper-provider.herokuapp.com) hosted on
|
359
|
-
heroku. For more demos check out [the
|
360
|
-
wiki](https://github.com/doorkeeper-gem/doorkeeper/wiki/Example-Applications).
|
361
|
-
|
362
376
|
### Screencast
|
363
377
|
|
364
378
|
Check out this screencast from [railscasts.com](http://railscasts.com/): [#353
|
@@ -376,15 +390,15 @@ here](https://github.com/doorkeeper-gem/doorkeeper/wiki/Testing-your-provider-wi
|
|
376
390
|
### Contributors
|
377
391
|
|
378
392
|
Thanks to all our [awesome
|
379
|
-
contributors](https://github.com/doorkeeper-gem/doorkeeper/contributors)!
|
393
|
+
contributors](https://github.com/doorkeeper-gem/doorkeeper/graphs/contributors)!
|
380
394
|
|
381
395
|
|
382
396
|
### IETF Standards
|
383
397
|
|
384
398
|
* [The OAuth 2.0 Authorization Framework](http://tools.ietf.org/html/rfc6749)
|
385
399
|
* [OAuth 2.0 Threat Model and Security Considerations](http://tools.ietf.org/html/rfc6819)
|
400
|
+
* [OAuth 2.0 Token Revocation](http://tools.ietf.org/html/rfc7009)
|
386
401
|
|
387
402
|
### License
|
388
403
|
|
389
404
|
MIT License. Copyright 2011 Applicake.
|
390
|
-
[http://applicake.com](http://applicake.com)
|
data/RELEASING.md
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
# Releasing doorkeeper
|
2
2
|
|
3
3
|
1. Update `lib/doorkeeper/version.rb` file accordingly.
|
4
|
-
2. Update `
|
4
|
+
2. Update `NEWS.md` to reflect the changes since last release.
|
5
5
|
3. Commit changes. There shouldn’t be code changes, and thus CI doesn’t need to
|
6
6
|
run, you can then add “[ci skip]” to the commit message.
|
7
|
-
4. Tag the release: `git tag vVERSION`
|
8
|
-
5. Push changes: `git push --tags`
|
7
|
+
4. Tag the release: `git tag vVERSION -m "Release vVERSION"`
|
8
|
+
5. Push changes: `git push && git push --tags`
|
9
9
|
6. Build and publish the gem:
|
10
|
+
|
10
11
|
```bash
|
11
12
|
gem build doorkeeper.gemspec
|
12
13
|
gem push doorkeeper-*.gem
|
13
14
|
```
|
15
|
+
|
14
16
|
7. Announce the new release, making sure to say “thank you” to the contributors
|
15
17
|
who helped shape this version!
|
@@ -45,9 +45,9 @@ module Doorkeeper
|
|
45
45
|
|
46
46
|
def application_params
|
47
47
|
if params.respond_to?(:permit)
|
48
|
-
params.require(:doorkeeper_application).permit(:name, :redirect_uri)
|
48
|
+
params.require(:doorkeeper_application).permit(:name, :redirect_uri, :scopes)
|
49
49
|
else
|
50
|
-
params[:doorkeeper_application].slice(:name, :redirect_uri) rescue nil
|
50
|
+
params[:doorkeeper_application].slice(:name, :redirect_uri, :scopes) rescue nil
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -17,8 +17,8 @@
|
|
17
17
|
<%= f.text_area :redirect_uri, class: 'form-control' %>
|
18
18
|
<%= doorkeeper_errors_for application, :redirect_uri %>
|
19
19
|
<span class="help-block">
|
20
|
-
|
21
|
-
|
20
|
+
<%= t('doorkeeper.applications.help.redirect_uri') %>
|
21
|
+
</span>
|
22
22
|
<% if Doorkeeper.configuration.native_redirect_uri %>
|
23
23
|
<span class="help-block">
|
24
24
|
<%= raw t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: "<code>#{ Doorkeeper.configuration.native_redirect_uri }</code>") %>
|
@@ -27,6 +27,17 @@
|
|
27
27
|
</div>
|
28
28
|
<% end %>
|
29
29
|
|
30
|
+
<%= content_tag :div, class: "form-group#{' has-error' if application.errors[:scopes].present?}" do %>
|
31
|
+
<%= f.label :scopes, class: 'col-sm-2 control-label' %>
|
32
|
+
<div class="col-sm-10">
|
33
|
+
<%= f.text_field :scopes, class: 'form-control' %>
|
34
|
+
<%= doorkeeper_errors_for application, :scopes %>
|
35
|
+
<span class="help-block">
|
36
|
+
<%= t('doorkeeper.applications.help.scopes') %>
|
37
|
+
</span>
|
38
|
+
</div>
|
39
|
+
<% end %>
|
40
|
+
|
30
41
|
<div class="form-group">
|
31
42
|
<div class="col-sm-offset-2 col-sm-10">
|
32
43
|
<%= f.submit t('doorkeeper.applications.buttons.submit'), class: "btn btn-primary" %>
|
@@ -5,13 +5,14 @@
|
|
5
5
|
<div class="row">
|
6
6
|
<div class="col-md-8">
|
7
7
|
<h4><%= t('.application_id') %>:</h4>
|
8
|
-
|
9
8
|
<p><code id="application_id"><%= @application.uid %></code></p>
|
10
9
|
|
11
10
|
<h4><%= t('.secret') %>:</h4>
|
12
|
-
|
13
11
|
<p><code id="secret"><%= @application.secret %></code></p>
|
14
12
|
|
13
|
+
<h4><%= t('.scopes') %>:</h4>
|
14
|
+
<p><code id="scopes"><%= @application.scopes %></code></p>
|
15
|
+
|
15
16
|
<h4><%= t('.callback_urls') %>:</h4>
|
16
17
|
|
17
18
|
<table>
|
@@ -9,8 +9,8 @@
|
|
9
9
|
<%= csrf_meta_tags %>
|
10
10
|
</head>
|
11
11
|
<body>
|
12
|
-
<div class="navbar navbar-inverse navbar-
|
13
|
-
<div class="container">
|
12
|
+
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
|
13
|
+
<div class="container-fluid">
|
14
14
|
<div class="navbar-header">
|
15
15
|
<%= link_to t('doorkeeper.layouts.admin.nav.oauth2_provider'), oauth_applications_path, class: 'navbar-brand' %>
|
16
16
|
</div>
|
@@ -18,6 +18,9 @@
|
|
18
18
|
<%= content_tag :li, class: "#{'active' if request.path == oauth_applications_path}" do %>
|
19
19
|
<%= link_to t('doorkeeper.layouts.admin.nav.applications'), oauth_applications_path %>
|
20
20
|
<% end %>
|
21
|
+
<%= content_tag :li do %>
|
22
|
+
<%= link_to 'Home', root_path %>
|
23
|
+
<% end %>
|
21
24
|
</ul>
|
22
25
|
</div>
|
23
26
|
</div>
|
data/config/locales/en.yml
CHANGED
@@ -14,36 +14,6 @@ en:
|
|
14
14
|
relative_uri: 'must be an absolute URI.'
|
15
15
|
secured_uri: 'must be an HTTPS/SSL URI.'
|
16
16
|
|
17
|
-
mongoid:
|
18
|
-
attributes:
|
19
|
-
doorkeeper/application:
|
20
|
-
name: 'Name'
|
21
|
-
redirect_uri: 'Redirect URI'
|
22
|
-
errors:
|
23
|
-
models:
|
24
|
-
doorkeeper/application:
|
25
|
-
attributes:
|
26
|
-
redirect_uri:
|
27
|
-
fragment_present: 'cannot contain a fragment.'
|
28
|
-
invalid_uri: 'must be a valid URI.'
|
29
|
-
relative_uri: 'must be an absolute URI.'
|
30
|
-
secured_uri: 'must be an HTTPS/SSL URI.'
|
31
|
-
|
32
|
-
mongo_mapper:
|
33
|
-
attributes:
|
34
|
-
doorkeeper/application:
|
35
|
-
name: 'Name'
|
36
|
-
redirect_uri: 'Redirect URI'
|
37
|
-
errors:
|
38
|
-
models:
|
39
|
-
doorkeeper/application:
|
40
|
-
attributes:
|
41
|
-
redirect_uri:
|
42
|
-
fragment_present: 'cannot contain a fragment.'
|
43
|
-
invalid_uri: 'must be a valid URI.'
|
44
|
-
relative_uri: 'must be an absolute URI.'
|
45
|
-
secured_uri: 'must be an HTTPS/SSL URI.'
|
46
|
-
|
47
17
|
doorkeeper:
|
48
18
|
applications:
|
49
19
|
confirmations:
|
@@ -59,6 +29,7 @@ en:
|
|
59
29
|
help:
|
60
30
|
redirect_uri: 'Use one line per URI'
|
61
31
|
native_redirect_uri: 'Use %{native_redirect_uri} for local tests'
|
32
|
+
scopes: 'Separate scopes with spaces. Leave blank to use the default scopes.'
|
62
33
|
edit:
|
63
34
|
title: 'Edit application'
|
64
35
|
index:
|
@@ -72,6 +43,7 @@ en:
|
|
72
43
|
title: 'Application: %{name}'
|
73
44
|
application_id: 'Application Id'
|
74
45
|
secret: 'Secret'
|
46
|
+
scopes: 'Scopes'
|
75
47
|
callback_urls: 'Callback urls'
|
76
48
|
actions: 'Actions'
|
77
49
|
|
@@ -82,7 +54,7 @@ en:
|
|
82
54
|
error:
|
83
55
|
title: 'An error has occurred'
|
84
56
|
new:
|
85
|
-
title: '
|
57
|
+
title: 'Authorization required'
|
86
58
|
prompt: 'Authorize %{client_name} to use your account?'
|
87
59
|
able_to: 'This application will be able to'
|
88
60
|
show:
|
@@ -148,4 +120,4 @@ en:
|
|
148
120
|
oauth2_provider: 'OAuth2 Provider'
|
149
121
|
applications: 'Applications'
|
150
122
|
application:
|
151
|
-
title: 'OAuth
|
123
|
+
title: 'OAuth authorization required'
|
data/doorkeeper.gemspec
CHANGED
@@ -8,24 +8,20 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["Felipe Elias Philipp", "Tute Costa"]
|
9
9
|
s.email = %w(tutecosta@gmail.com)
|
10
10
|
s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
|
11
|
-
s.summary = "
|
12
|
-
s.description = "Doorkeeper is an OAuth 2 provider for Rails."
|
11
|
+
s.summary = "OAuth 2 provider for Rails and Grape"
|
12
|
+
s.description = "Doorkeeper is an OAuth 2 provider for Rails and Grape."
|
13
13
|
s.license = 'MIT'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
|
-
s.test_files = `git ls-files --
|
16
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
19
|
s.add_dependency "railties", ">= 3.2"
|
20
20
|
|
21
|
-
s.add_development_dependency "
|
22
|
-
s.add_development_dependency "rspec-rails", "~> 2.99.0"
|
21
|
+
s.add_development_dependency "rspec-rails", "~> 3.4.0"
|
23
22
|
s.add_development_dependency "capybara", "~> 2.3.0"
|
24
23
|
s.add_development_dependency "generator_spec", "~> 0.9.0"
|
25
24
|
s.add_development_dependency "factory_girl", "~> 4.5.0"
|
26
25
|
s.add_development_dependency "timecop", "~> 0.7.0"
|
27
26
|
s.add_development_dependency "database_cleaner", "~> 1.3.0"
|
28
|
-
s.add_development_dependency "rspec-activemodel-mocks", "~> 1.0.0"
|
29
|
-
s.add_development_dependency "bcrypt-ruby", "~> 3.0.1"
|
30
|
-
s.add_development_dependency "pry", "~> 0.10.0"
|
31
27
|
end
|
data/lib/doorkeeper/config.rb
CHANGED
@@ -7,54 +7,38 @@ module Doorkeeper
|
|
7
7
|
|
8
8
|
def self.configure(&block)
|
9
9
|
@config = Config::Builder.new(&block).build
|
10
|
-
|
11
|
-
|
10
|
+
setup_orm_adapter
|
11
|
+
setup_orm_models
|
12
12
|
setup_application_owner if @config.enable_application_owner?
|
13
|
+
check_requirements
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.configuration
|
16
17
|
@config || (fail MissingConfiguration.new)
|
17
18
|
end
|
18
19
|
|
19
|
-
def self.
|
20
|
-
|
21
|
-
ActiveRecord::Base.connected? &&
|
22
|
-
ActiveRecord::Base.connection.table_exists?(
|
23
|
-
Doorkeeper::Application.table_name
|
24
|
-
) &&
|
25
|
-
!Doorkeeper::Application.new.attributes.include?("scopes")
|
26
|
-
|
27
|
-
puts <<-MSG.squish
|
28
|
-
[doorkeeper] Missing column: `oauth_applications.scopes`.
|
29
|
-
If you are using ActiveRecord run `rails generate doorkeeper:application_scopes
|
30
|
-
&& rake db:migrate` to add it.
|
31
|
-
MSG
|
32
|
-
end
|
20
|
+
def self.check_requirements
|
21
|
+
@orm_adapter.check_requirements!(configuration)
|
33
22
|
end
|
34
23
|
|
35
|
-
def self.
|
36
|
-
|
37
|
-
class_name.constantize.initialize_models!
|
24
|
+
def self.setup_orm_adapter
|
25
|
+
@orm_adapter = "doorkeeper/orm/#{configuration.orm}".classify.constantize
|
38
26
|
rescue NameError => e
|
39
|
-
|
40
|
-
fail e, "ORM adapter not found (#{configuration.orm})", <<-error_msg
|
27
|
+
fail e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.squish
|
41
28
|
[doorkeeper] ORM adapter not found (#{configuration.orm}), or there was an error
|
42
29
|
trying to load it.
|
43
30
|
|
44
31
|
You probably need to add the related gem for this adapter to work with
|
45
32
|
doorkeeper.
|
33
|
+
ERROR_MSG
|
34
|
+
end
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
error_msg
|
50
|
-
else
|
51
|
-
raise e
|
52
|
-
end
|
36
|
+
def self.setup_orm_models
|
37
|
+
@orm_adapter.initialize_models!
|
53
38
|
end
|
54
39
|
|
55
40
|
def self.setup_application_owner
|
56
|
-
|
57
|
-
Application.send :include, Models::Ownership
|
41
|
+
@orm_adapter.initialize_application_owner!
|
58
42
|
end
|
59
43
|
|
60
44
|
class Config
|
@@ -108,6 +92,12 @@ and that your `initialize_models!` method doesn't raise any errors.\n
|
|
108
92
|
def force_ssl_in_redirect_uri(boolean)
|
109
93
|
@config.instance_variable_set("@force_ssl_in_redirect_uri", boolean)
|
110
94
|
end
|
95
|
+
|
96
|
+
def access_token_generator(access_token_generator)
|
97
|
+
@config.instance_variable_set(
|
98
|
+
'@access_token_generator', access_token_generator
|
99
|
+
)
|
100
|
+
end
|
111
101
|
end
|
112
102
|
|
113
103
|
module Option
|
@@ -198,6 +188,7 @@ and that your `initialize_models!` method doesn't raise any errors.\n
|
|
198
188
|
option :realm, default: 'Doorkeeper'
|
199
189
|
option :force_ssl_in_redirect_uri, default: !Rails.env.development?
|
200
190
|
option :grant_flows, default: %w(authorization_code client_credentials)
|
191
|
+
option :access_token_generator, default: "Doorkeeper::OAuth::Helpers::UniqueToken"
|
201
192
|
|
202
193
|
attr_reader :reuse_access_token
|
203
194
|
|
data/lib/doorkeeper/engine.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
module Doorkeeper
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
initializer "doorkeeper.params.filter" do |app|
|
4
|
-
app.config.filter_parameters +=
|
4
|
+
app.config.filter_parameters += [:client_secret, :code, :token]
|
5
|
+
end
|
6
|
+
|
7
|
+
initializer "doorkeeper.locales" do |app|
|
8
|
+
if app.config.i18n.fallbacks.blank?
|
9
|
+
app.config.i18n.fallbacks = [:en]
|
10
|
+
end
|
5
11
|
end
|
6
12
|
|
7
13
|
initializer "doorkeeper.routes" do
|
data/lib/doorkeeper/errors.rb
CHANGED
@@ -6,10 +6,22 @@ module Doorkeeper
|
|
6
6
|
class InvalidAuthorizationStrategy < DoorkeeperError
|
7
7
|
end
|
8
8
|
|
9
|
+
class InvalidTokenReuse < DoorkeeperError
|
10
|
+
end
|
11
|
+
|
12
|
+
class InvalidGrantReuse < DoorkeeperError
|
13
|
+
end
|
14
|
+
|
9
15
|
class InvalidTokenStrategy < DoorkeeperError
|
10
16
|
end
|
11
17
|
|
12
18
|
class MissingRequestStrategy < DoorkeeperError
|
13
19
|
end
|
20
|
+
|
21
|
+
class UnableToGenerateToken < DoorkeeperError
|
22
|
+
end
|
23
|
+
|
24
|
+
class TokenGeneratorNotFound < DoorkeeperError
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
@@ -41,6 +41,12 @@ module Doorkeeper
|
|
41
41
|
:unsupported_response_type
|
42
42
|
when Errors::MissingRequestStrategy
|
43
43
|
:invalid_request
|
44
|
+
when Errors::InvalidTokenReuse
|
45
|
+
:invalid_request
|
46
|
+
when Errors::InvalidGrantReuse
|
47
|
+
:invalid_grant
|
48
|
+
when Errors::DoorkeeperError
|
49
|
+
exception.message
|
44
50
|
end
|
45
51
|
|
46
52
|
OAuth::ErrorResponse.new name: error_name, state: params[:state]
|
@@ -7,11 +7,12 @@ module Doorkeeper
|
|
7
7
|
include Models::Revocable
|
8
8
|
include Models::Accessible
|
9
9
|
include Models::Scopes
|
10
|
+
include ActiveModel::MassAssignmentSecurity if defined?(::ProtectedAttributes)
|
10
11
|
|
11
12
|
included do
|
12
13
|
belongs_to :application, class_name: 'Doorkeeper::Application', inverse_of: :access_grants
|
13
14
|
|
14
|
-
if
|
15
|
+
if respond_to?(:attr_accessible)
|
15
16
|
attr_accessible :resource_owner_id, :application_id, :expires_in, :redirect_uri, :scopes
|
16
17
|
end
|
17
18
|
|
@@ -23,7 +24,7 @@ module Doorkeeper
|
|
23
24
|
|
24
25
|
module ClassMethods
|
25
26
|
def by_token(token)
|
26
|
-
where(token: token).limit(1).to_a.first
|
27
|
+
where(token: token.to_s).limit(1).to_a.first
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
@@ -7,6 +7,7 @@ module Doorkeeper
|
|
7
7
|
include Models::Revocable
|
8
8
|
include Models::Accessible
|
9
9
|
include Models::Scopes
|
10
|
+
include ActiveModel::MassAssignmentSecurity if defined?(::ProtectedAttributes)
|
10
11
|
|
11
12
|
included do
|
12
13
|
belongs_to :application,
|
@@ -18,7 +19,7 @@ module Doorkeeper
|
|
18
19
|
|
19
20
|
attr_writer :use_refresh_token
|
20
21
|
|
21
|
-
if
|
22
|
+
if respond_to?(:attr_accessible)
|
22
23
|
attr_accessible :application_id, :resource_owner_id, :expires_in,
|
23
24
|
:scopes, :use_refresh_token
|
24
25
|
end
|
@@ -31,11 +32,11 @@ module Doorkeeper
|
|
31
32
|
|
32
33
|
module ClassMethods
|
33
34
|
def by_token(token)
|
34
|
-
where(token: token).limit(1).to_a.first
|
35
|
+
where(token: token.to_s).limit(1).to_a.first
|
35
36
|
end
|
36
37
|
|
37
38
|
def by_refresh_token(refresh_token)
|
38
|
-
where(refresh_token: refresh_token).first
|
39
|
+
where(refresh_token: refresh_token.to_s).first
|
39
40
|
end
|
40
41
|
|
41
42
|
def revoke_all_for(application_id, resource_owner)
|
@@ -128,7 +129,14 @@ module Doorkeeper
|
|
128
129
|
end
|
129
130
|
|
130
131
|
def generate_token
|
131
|
-
|
132
|
+
generator = Doorkeeper.configuration.access_token_generator.constantize
|
133
|
+
self.token = generator.generate(resource_owner_id: resource_owner_id,
|
134
|
+
scopes: scopes, application: application,
|
135
|
+
expires_in: expires_in)
|
136
|
+
rescue NoMethodError
|
137
|
+
raise Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`."
|
138
|
+
rescue NameError
|
139
|
+
raise Errors::TokenGeneratorNotFound, "#{generator} not found"
|
132
140
|
end
|
133
141
|
end
|
134
142
|
end
|