Sha256: 7d11244d95e55229707609d1f80178499d0e8010739704ebde624c647383cae5

Contents?: true

Size: 706 Bytes

Versions: 2

Compression:

Stored size: 706 Bytes

Contents

require 'oa2c/oauth2_token'
module Oa2c
  class AccessToken
    include Mongoid::Document
    include OAuth2Token

    belongs_to :refresh_token

    def to_bearer_token(with_refresh_token = false)
      Rack::OAuth2::AccessToken::Bearer.new(access_token: token, expires_in: expires_in).tap do |bearer_token|
        if with_refresh_token
          bearer_token.refresh_token = create_refresh_token(user: user, client: client).token
        end
      end
    end

    private

    def setup
      super
      if 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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oa2c-0.0.2 app/models/oa2c/access_token.rb
oa2c-0.0.1 app/models/oa2c/access_token.rb