Sha256: f3be5af51566f72034a8806ddedb01606120f559ca29e0dc363bc42213e64d4d

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Osso
  module Models
    class AccessToken < ::ActiveRecord::Base
      include OAuth2Token
      self.default_lifetime = 10.minutes
      belongs_to :refresh_token

      def to_bearer_token
        Rack::OAuth2::AccessToken::Bearer.new(
          access_token: token,
          expires_in: expires_in,
        )
      end

      private

      def setup
        super
        return unless refresh_token

        self.user = refresh_token.user
        self.client = refresh_token.client
        self.expires_at = [expires_at, refresh_token.expires_at].min
      end
    end
  end
end

# == Schema Information
#
# Table name: access_tokens
#
#  id              :uuid             not null, primary key
#  token           :string
#  expires_at      :datetime
#  created_at      :datetime         not null
#  updated_at      :datetime         not null
#  user_id         :uuid
#  oauth_client_id :uuid
#  requested       :jsonb
#
# Indexes
#
#  index_access_tokens_on_oauth_client_id       (oauth_client_id)
#  index_access_tokens_on_token_and_expires_at  (token,expires_at) UNIQUE
#  index_access_tokens_on_user_id               (user_id)
#

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
osso-0.1.2 lib/osso/models/access_token.rb
osso-0.1.1 lib/osso/models/access_token.rb
osso-0.1.0 lib/osso/models/access_token.rb
osso-0.0.11 lib/osso/models/access_token.rb
osso-0.0.10 lib/osso/models/access_token.rb
osso-0.0.8 lib/osso/models/access_token.rb
osso-0.0.7 lib/osso/models/access_token.rb
osso-0.0.6 lib/osso/models/access_token.rb
osso-0.0.6.alpha lib/osso/models/access_token.rb
osso-0.0.5 lib/osso/models/access_token.rb