Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
02709334
Commit
02709334
authored
Jun 29, 2018
by
Francisco Javier López
Committed by
Sean McGivern
Jun 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enabling Doorkeeper reuse_access_token option
parent
3223771b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
1 deletion
+62
-1
changelogs/unreleased/fj-46278-enable-doorkeeper-reuse-access-token.yml
...eleased/fj-46278-enable-doorkeeper-reuse-access-token.yml
+6
-0
config/initializers/doorkeeper.rb
config/initializers/doorkeeper.rb
+1
-1
spec/requests/oauth_tokens_spec.rb
spec/requests/oauth_tokens_spec.rb
+55
-0
No files found.
changelogs/unreleased/fj-46278-enable-doorkeeper-reuse-access-token.yml
0 → 100644
View file @
02709334
---
title
:
Enable Doorkeeper option to avoid generating new tokens when users login via
oauth
merge_request
:
20200
author
:
type
:
fixed
config/initializers/doorkeeper.rb
View file @
02709334
...
...
@@ -37,7 +37,7 @@ Doorkeeper.configure do
# Reuse access token for the same resource owner within an application (disabled by default)
# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
#
reuse_access_token
reuse_access_token
# Issue access tokens with refresh token (disabled by default)
use_refresh_token
...
...
spec/requests/oauth_tokens_spec.rb
0 → 100644
View file @
02709334
require
'spec_helper'
describe
'OAuth Tokens requests'
do
let
(
:user
)
{
create
:user
}
let
(
:application
)
{
create
:oauth_application
,
scopes:
'api'
}
def
request_access_token
(
user
)
post
'/oauth/token'
,
grant_type:
'authorization_code'
,
code:
generate_access_grant
(
user
).
token
,
redirect_uri:
application
.
redirect_uri
,
client_id:
application
.
uid
,
client_secret:
application
.
secret
end
def
generate_access_grant
(
user
)
create
:oauth_access_grant
,
application:
application
,
resource_owner_id:
user
.
id
end
context
'when there is already a token for the application'
do
let!
(
:existing_token
)
{
create
:oauth_access_token
,
application:
application
,
resource_owner_id:
user
.
id
}
context
'and the request is done by the resource owner'
do
it
'reuses and returns the stored token'
do
expect
do
request_access_token
(
user
)
end
.
not_to
change
{
Doorkeeper
::
AccessToken
.
count
}
expect
(
json_response
[
'access_token'
]).
to
eq
existing_token
.
token
end
end
context
'and the request is done by a different user'
do
let
(
:other_user
)
{
create
:user
}
it
'generates and returns a different token for a different owner'
do
expect
do
request_access_token
(
other_user
)
end
.
to
change
{
Doorkeeper
::
AccessToken
.
count
}.
by
(
1
)
expect
(
json_response
[
'access_token'
]).
not_to
be_nil
end
end
end
context
'when there is no token stored for the application'
do
it
'generates and returns a new token'
do
expect
do
request_access_token
(
user
)
end
.
to
change
{
Doorkeeper
::
AccessToken
.
count
}.
by
(
1
)
expect
(
json_response
[
'access_token'
]).
not_to
be_nil
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment