Skip to content

Commit 40fc261

Browse files
committed
Enable get access_token via URL.
1 parent bf40224 commit 40fc261

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

.yamllint

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extends: default
2+
3+
rules:
4+
line-length:
5+
max: 120
6+
level: warning

Gemfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ GEM
8989
ffi (1.10.0-x86-mingw32)
9090
globalid (0.4.2)
9191
activesupport (>= 4.2.0)
92-
i18n (1.5.3)
92+
i18n (1.6.0)
9393
concurrent-ruby (~> 1.0)
9494
io-like (0.3.0)
9595
jbuilder (2.8.0)

config/initializers/doorkeeper.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
# User.find_by_id(session[:user_id]) || redirect_to(new_user_session_url)
1111
end
1212

13+
# In this flow, a token is requested in exchange for the resource owner credentials (email and password)
14+
resource_owner_from_credentials do |_routes|
15+
user = User.find_for_database_authentication(email: params[:email])
16+
user&.valid_for_authentication? { user.valid_password?(params[:password]) } && user
17+
end
18+
1319
# If you didn't skip applications controller from Doorkeeper routes in your application routes.rb
1420
# file then you need to declare this block in order to restrict access to the web interface for
1521
# adding oauth authorized applications. In other case it will return 403 Forbidden response
@@ -181,7 +187,7 @@
181187
# http://tools.ietf.org/html/rfc6819#section-4.4.2
182188
# http://tools.ietf.org/html/rfc6819#section-4.4.3
183189
#
184-
# grant_flows %w[authorization_code client_credentials]
190+
grant_flows %w[authorization_code client_credentials password]
185191

186192
# Hook into the strategies' request & response life-cycle in case your
187193
# application needs advanced customization or logging:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'test_helper'
2+
3+
class DoorkeeperControllerTest < ActionDispatch::IntegrationTest
4+
test 'should get token' do
5+
post oauth_token_url, params: { email: '[email protected]',
6+
password: '123456',
7+
grant_type: 'password' }
8+
assert_response :success
9+
assert_match 'Bearer', JSON.parse(@response.body)['token_type']
10+
end
11+
end

test/fixtures/users.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
eric:
33
44
confirmed_at: <%= Time.zone.now %>
5+
# password: 123456
6+
encrypted_password: '$2a$11$I3DE/JkhWB03DUC.LFaoEuwVRU7Kk474udMsmF/AiX5IAxm5CoXcS'

0 commit comments

Comments
 (0)