module Doorkeeper::AccessTokenMixin
Public Instance Methods
Indicates if token is acceptable for specific scopes.
@param scopes [Array<String>] scopes
@return [Boolean] true if record is accessible and includes scopes or
false in other cases
# File lib/doorkeeper/models/access_token_mixin.rb, line 199 def acceptable?(scopes) accessible? && includes_scope?(*scopes) end
JSON representation of the Access Token instance.
@return [Hash] hash with token data
# File lib/doorkeeper/models/access_token_mixin.rb, line 170 def as_json(_options = {}) { resource_owner_id: resource_owner_id, scopes: scopes, expires_in_seconds: expires_in_seconds, application: { uid: application.try(:uid) }, created_at: created_at.to_i } end
Indicates whether the token instance have the same credential as the other Access Token.
@param access_token [Doorkeeper::AccessToken] other token
@return [Boolean] true if credentials are same of false in other cases
# File lib/doorkeeper/models/access_token_mixin.rb, line 187 def same_credential?(access_token) application_id == access_token.application_id && resource_owner_id == access_token.resource_owner_id end
Access Token type: Bearer. @see tools.ietf.org/html/rfc6750
The OAuth 2.0 Authorization Framework: Bearer Token Usage
# File lib/doorkeeper/models/access_token_mixin.rb, line 158 def token_type 'bearer' end
# File lib/doorkeeper/models/access_token_mixin.rb, line 162 def use_refresh_token? @use_refresh_token ||= false !!@use_refresh_token end
Private Instance Methods
Generates refresh token with UniqueToken generator.
@return [String] refresh token value
# File lib/doorkeeper/models/access_token_mixin.rb, line 209 def generate_refresh_token self.refresh_token = UniqueToken.generate end
Generates and sets the token value with the configured Generator class (see Doorkeeper.configuration).
@return [String] generated token value
@raise [Doorkeeper::Errors::UnableToGenerateToken]
custom class doesn't implement .generate method
@raise [Doorkeeper::Errors::TokenGeneratorNotFound]
custom class doesn't exist
# File lib/doorkeeper/models/access_token_mixin.rb, line 223 def generate_token self.created_at ||= Time.now.utc self.token = token_generator.generate( resource_owner_id: resource_owner_id, scopes: scopes, application: application, expires_in: expires_in, created_at: created_at ) end
# File lib/doorkeeper/models/access_token_mixin.rb, line 235 def token_generator generator_name = Doorkeeper.configuration.access_token_generator generator = generator_name.constantize return generator if generator.respond_to?(:generate) raise Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`." rescue NameError raise Errors::TokenGeneratorNotFound, "#{generator_name} not found" end