Module: DoorkeeperMongodb::Mixins::Mongoid::ApplicationMixin

Extended by:
ActiveSupport::Concern
Includes:
Doorkeeper::Models::Scopes, Doorkeeper::Models::SecretStorable, Doorkeeper::OAuth::Helpers, BaseMixin
Included in:
Doorkeeper::Application
Defined in:
lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#as_json(options = {}) ⇒ Object



224
225
226
227
228
229
230
231
232
# File 'lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb', line 224

def as_json(options = {})
  hash = super

  if hash.key?("_id") || (options && Array.wrap(options[:only]).include?(:id))
    hash["id"] = id.to_s
  end
  hash["secret"] = plaintext_secret if hash.key?("secret")
  hash
end

#authorized_for_resource_owner?(resource_owner) ⇒ Boolean

Returns:

  • (Boolean)


234
235
236
# File 'lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb', line 234

def authorized_for_resource_owner?(resource_owner)
  Doorkeeper.configuration.authorize_resource_owner_for_client.call(self, resource_owner)
end

#plaintext_secretObject



216
217
218
219
220
221
222
# File 'lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb', line 216

def plaintext_secret
  if secret_strategy.allows_restoring_secrets?
    secret_strategy.restore_secret(self, :secret)
  else
    @raw_secret
  end
end

#redirect_uri=(uris) ⇒ String

Set an application’s valid redirect URIs.

Parameters:

  • uris (String, Array)

    Newline-separated string or array the URI(s)

Returns:

  • (String)

    The redirect URI(s) seperated by newlines.



207
208
209
# File 'lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb', line 207

def redirect_uri=(uris)
  super(uris.is_a?(Array) ? uris.join("\n") : uris)
end

#renew_secretObject



211
212
213
214
# File 'lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb', line 211

def renew_secret
  @raw_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate
  secret_strategy.store_secret(self, :secret, @raw_secret)
end

#secret_matches?(input) ⇒ Boolean

Returns:

  • (Boolean)


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb', line 185

def secret_matches?(input)
  # return false if either is nil, since secure_compare depends on strings
  # but Application secrets MAY be nil depending on confidentiality.
  return false if input.nil? || secret.nil?

  # When matching the secret by comparer function, all is well.
  return true if secret_strategy.secret_matches?(input, secret)

  # When fallback lookup is enabled, ensure applications
  # with plain secrets can still be found
  if fallback_secret_strategy
    fallback_secret_strategy.secret_matches?(input, secret)
  else
    false
  end
end