Sha256: d95083699d5040bf98c190b18462c225d836f598bf03c9a262cbffebd960a0e9

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

require 'expirable_token'

class AccessToken < ActiveRecord::Base
  include ExpirableToken
  self.default_lifetime = 15.minutes
  attr_accessor :refresh_token

  def to_bearer_token(with_refresh_token = false)
    bearer_token = Rack::OAuth2::AccessToken::Bearer.new(
      :access_token => self.token,
      :expires_in => self.expires_in
    )
    if with_refresh_token
      refresh_token = client.refresh_tokens.create! :user => self.user
      bearer_token.refresh_token = refresh_token.token
    end
    bearer_token
  end

  private

  def setup
    super
    if refresh_token
      self.user = refresh_token.user
      self.client = refresh_token.client
      self.expires_at = [self.expires_at, refresh_token.expires_at].min
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise_oauth2_providable-0.1.6 app/models/access_token.rb