Module: OAuth2::Provider::Models::AccessToken

Extended by:
ActiveSupport::Concern
Defined in:
lib/oauth2/provider/models/access_token.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object


22
23
24
25
26
27
# File 'lib/oauth2/provider/models/access_token.rb', line 22

def as_json(options = {})
  {"access_token" => access_token}.tap do |result|
    result["expires_in"] = expires_in if expires_at.present?
    result["refresh_token"] = refresh_token if refresh_token.present?
  end
end

#initialize(attributes = {}, *args, &block) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/oauth2/provider/models/access_token.rb', line 14

def initialize(attributes = {}, *args, &block)
  attributes ||= {} # Mongoid passes in nil
  super attributes.reverse_merge(
    :access_token => self.class.unique_random_token(:access_token),
    :refresh_token => self.class.unique_random_token(:refresh_token)
  )
end

#refreshable?Boolean


29
30
31
# File 'lib/oauth2/provider/models/access_token.rb', line 29

def refreshable?
  refresh_token.present? && authorization.fresh?
end