Skip to content

Commit

Permalink
Extract attributes for token generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Feb 6, 2020
1 parent 6c3fd03 commit fd7ef6c
Show file tree
Hide file tree
Showing 2 changed files with 522 additions and 504 deletions.
22 changes: 17 additions & 5 deletions lib/doorkeeper/models/access_token_mixin.rb
Expand Up @@ -384,16 +384,28 @@ def generate_refresh_token
def generate_token
self.created_at ||= Time.now.utc

@raw_token = token_generator.generate(
@raw_token = token_generator.generate(attributes_for_token_generator)
secret_strategy.store_secret(self, :token, @raw_token)
@raw_token
end

# Set of attributes that would be passed to token generator to
# generate unique token based on them.
#
# @return [Hash] set of attributes
#
def attributes_for_token_generator
{
resource_owner_id: resource_owner_id,
scopes: scopes,
application: application,
expires_in: expires_in,
created_at: created_at,
)

secret_strategy.store_secret(self, :token, @raw_token)
@raw_token
}.tap do |attributes|
if Doorkeeper.config.polymorphic_resource_owner?
attributes[:resource_owner] = resource_owner
end
end
end

def token_generator
Expand Down

0 comments on commit fd7ef6c

Please sign in to comment.