debian-mirror-gitlab/app/models/oauth_access_token.rb
2022-08-27 11:52:29 +05:30

30 lines
974 B
Ruby

# frozen_string_literal: true
class OauthAccessToken < Doorkeeper::AccessToken
belongs_to :resource_owner, class_name: 'User'
belongs_to :application, class_name: 'Doorkeeper::Application'
alias_attribute :user, :resource_owner
scope :latest_per_application, -> { select('distinct on(application_id) *').order(application_id: :desc, created_at: :desc) }
scope :preload_application, -> { preload(:application) }
def scopes=(value)
if value.is_a?(Array)
super(Doorkeeper::OAuth::Scopes.from_array(value).to_s)
else
super
end
end
# this method overrides a shortcoming upstream, more context:
# https://gitlab.com/gitlab-org/gitlab/-/issues/367888
def self.find_by_fallback_token(attr, plain_secret)
return unless fallback_secret_strategy && fallback_secret_strategy == Doorkeeper::SecretStoring::Plain
# token is hashed, don't allow plaintext comparison
return if plain_secret.starts_with?("$")
super
end
end