You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a new token for an application, despite passing an application object into the method, it's refetched from the database when the token is generated.
When passing an object into the find_or_create_for method, it should use that object reference rather than refetching the application object from the DB.
Because :application is used as a keyword argument, it's removed from the token_attributes hash which is passed further down into the create! method. Anytime a new AccessToken is created, generate_token is called which in turn calls attributes_for_token_generator, which passes a full application reference to the token generator.
# Set of attributes that would be passed to token generator to# generate unique token based on them.## @return [Hash] set of attributes#defattributes_for_token_generator{resource_owner_id: resource_owner_id,scopes: scopes,application: application,# see here, this causes a refetchexpires_in: expires_in,created_at: created_at,}.tapdo |attributes|
ifDoorkeeper.config.polymorphic_resource_owner?attributes[:resource_owner]=resource_ownerendendend
Because the create! method is only getting passed the application_id and not the full application, when application is called from inside attributes_for_token_generator it causes the application to be fetched from the database again.
This could be avoided by passing the application into token_attributes rather than passing in the id only.
System configuration
Doorkeeper 5.4.0
The text was updated successfully, but these errors were encountered:
This avoids refetching the application object from the database when it's referenced inside of `attributes_for_token_generator`. Closesdoorkeeper-gem#1574
This avoids refetching the application object from the database when it's referenced inside of `attributes_for_token_generator`. Closesdoorkeeper-gem#1574
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
When creating a new token for an application, despite passing an application object into the method, it's refetched from the database when the token is generated.
Steps to reproduce
Create a token for an existing application:
Expected behavior
When passing an object into the
find_or_create_for
method, it should use that object reference rather than refetching the application object from the DB.Actual behavior
Here is the
create_for(...)
methodBecause
:application
is used as a keyword argument, it's removed from thetoken_attributes
hash which is passed further down into thecreate!
method. Anytime a newAccessToken
is created,generate_token
is called which in turn callsattributes_for_token_generator
, which passes a full application reference to the token generator.Because the
create!
method is only getting passed theapplication_id
and not the full application, whenapplication
is called from insideattributes_for_token_generator
it causes the application to be fetched from the database again.This could be avoided by passing the application into
token_attributes
rather than passing in theid
only.System configuration
Doorkeeper 5.4.0
The text was updated successfully, but these errors were encountered: