Sha256: e0330c9ded494621cd9f80b22ca20ca3c3accce95f19a6be11ed7aa26cbaa6c4

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

module Sso
  class Client < ActiveRecord::Base
    include ::Sso::Logging

    belongs_to :session, class_name: 'Sso::Session', foreign_key: :sso_session_id
    belongs_to :application, class_name: 'Doorkeeper::Application',  inverse_of: :sso_clients
    belongs_to :access_grant, class_name: 'Doorkeeper::AccessGrant', inverse_of: :sso_client
    belongs_to :access_token, class_name: 'Doorkeeper::AccessToken', inverse_of: :sso_client

    validates :access_grant_id, uniqueness: { allow_nil: true }
    validates :access_token_id, uniqueness: { allow_nil: true }

    scope :with_access_grant, -> { where.not(access_grant: nil) }
    scope :with_access_token, -> { where.not(access_token: nil) }

    class << self
      def find_by_grant_token(token)
        find_by(access_grant: ::Doorkeeper::AccessGrant.by_token(token))
      end

      def find_by_access_token(token)
        find_by(access_token: ::Doorkeeper::AccessToken.by_token(token))
      end

      def create_from_access_token(session, token_id)
        return false unless oauth_token = ::Doorkeeper::AccessToken.find_by(id: token_id)
        client = session.find_or_create_by(access_token_id: token_id)
      end
    end

    def update_access_token(token)
      return false unless oauth_token = ::Doorkeeper::AccessToken.by_token(token)
      update(access_token_id: oauth_token.id, application_id: oauth_token.application.id)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper_sso-0.4.9 app/models/sso/client.rb
doorkeeper_sso-0.4.8 app/models/sso/client.rb