Module: Doorkeeper

Defined in:
lib/doorkeeper.rb,
lib/doorkeeper/errors.rb,
lib/doorkeeper/config.rb,
lib/doorkeeper/engine.rb,
lib/doorkeeper/server.rb,
lib/doorkeeper/request.rb,
lib/doorkeeper/version.rb,
lib/doorkeeper/oauth/token.rb,
lib/doorkeeper/validations.rb,
lib/doorkeeper/oauth/error.rb,
lib/doorkeeper/orm/mongoid2.rb,
lib/doorkeeper/rails/routes.rb,
lib/doorkeeper/orm/mongoid3.rb,
lib/doorkeeper/orm/mongoid4.rb,
lib/doorkeeper/oauth/client.rb,
lib/doorkeeper/request/code.rb,
lib/doorkeeper/oauth/scopes.rb,
lib/doorkeeper/rails/helpers.rb,
lib/doorkeeper/request/token.rb,
lib/doorkeeper/orm/mongo_mapper.rb,
lib/doorkeeper/request/password.rb,
lib/doorkeeper/orm/active_record.rb,
lib/doorkeeper/oauth/code_request.rb,
lib/doorkeeper/helpers/controller.rb,
lib/doorkeeper/rails/routes/mapper.rb,
lib/doorkeeper/oauth/code_response.rb,
lib/doorkeeper/oauth/token_request.rb,
lib/doorkeeper/rails/routes/mapping.rb,
lib/doorkeeper/oauth/client/methods.rb,
lib/doorkeeper/oauth/error_response.rb,
lib/doorkeeper/oauth/token_response.rb,
lib/doorkeeper/oauth/request_concern.rb,
lib/doorkeeper/request/refresh_token.rb,
lib/doorkeeper/models/concerns/scopes.rb,
lib/doorkeeper/oauth/pre_authorization.rb,
lib/doorkeeper/orm/mongoid2/application.rb,
lib/doorkeeper/oauth/authorization/code.rb,
lib/doorkeeper/oauth/client/credentials.rb,
lib/doorkeeper/models/application_mixin.rb,
lib/doorkeeper/orm/mongoid3/application.rb,
lib/doorkeeper/orm/mongoid4/application.rb,
lib/doorkeeper/orm/mongoid3/access_token.rb,
lib/doorkeeper/models/concerns/expirable.rb,
lib/doorkeeper/orm/mongoid4/access_grant.rb,
lib/doorkeeper/orm/mongoid3/access_grant.rb,
lib/doorkeeper/orm/mongoid4/access_token.rb,
lib/doorkeeper/models/concerns/ownership.rb,
lib/doorkeeper/models/concerns/revocable.rb,
lib/doorkeeper/models/access_token_mixin.rb,
lib/doorkeeper/models/access_grant_mixin.rb,
lib/doorkeeper/orm/mongoid2/access_grant.rb,
lib/doorkeeper/oauth/helpers/uri_checker.rb,
lib/doorkeeper/orm/mongoid2/access_token.rb,
lib/doorkeeper/oauth/authorization/token.rb,
lib/doorkeeper/request/authorization_code.rb,
lib/doorkeeper/oauth/helpers/unique_token.rb,
lib/doorkeeper/models/concerns/accessible.rb,
lib/doorkeeper/request/client_credentials.rb,
lib/generators/doorkeeper/views_generator.rb,
lib/doorkeeper/oauth/helpers/scope_checker.rb,
lib/doorkeeper/oauth/refresh_token_request.rb,
lib/doorkeeper/oauth/invalid_token_response.rb,
lib/doorkeeper/orm/mongoid4/concerns/scopes.rb,
lib/doorkeeper/orm/mongoid2/concerns/scopes.rb,
lib/doorkeeper/orm/mongo_mapper/application.rb,
lib/doorkeeper/orm/mongoid3/concerns/scopes.rb,
lib/doorkeeper/orm/mongo_mapper/access_grant.rb,
lib/doorkeeper/orm/active_record/application.rb,
app/controllers/doorkeeper/tokens_controller.rb,
lib/doorkeeper/orm/mongo_mapper/access_token.rb,
lib/doorkeeper/orm/active_record/access_token.rb,
lib/doorkeeper/orm/active_record/access_grant.rb,
lib/doorkeeper/oauth/forbidden_token_response.rb,
lib/doorkeeper/oauth/client_credentials/issuer.rb,
lib/doorkeeper/oauth/authorization/uri_builder.rb,
lib/doorkeeper/oauth/client_credentials_request.rb,
lib/doorkeeper/oauth/authorization_code_request.rb,
lib/doorkeeper/oauth/client_credentials/creator.rb,
app/controllers/doorkeeper/token_info_controller.rb,
app/controllers/doorkeeper/application_controller.rb,
lib/doorkeeper/oauth/client_credentials/validation.rb,
app/controllers/doorkeeper/applications_controller.rb,
lib/doorkeeper/oauth/password_access_token_request.rb,
app/controllers/doorkeeper/authorizations_controller.rb,
app/controllers/doorkeeper/application_metal_controller.rb,
app/controllers/doorkeeper/authorized_applications_controller.rb,
lib/doorkeeper/generators/doorkeeper/mongo_mapper/indexes_generator.rb

Defined Under Namespace

Modules: AccessGrantMixin, AccessTokenMixin, ApplicationMixin, DashboardHelper, Errors, Generators, Helpers, Models, MongoMapper, OAuth, Orm, Rails, Request, Validations Classes: AccessGrant, AccessToken, Application, ApplicationController, ApplicationMetalController, ApplicationOwnerGenerator, ApplicationScopesGenerator, ApplicationsController, AuthorizationsController, AuthorizedApplicationsController, Config, Engine, InstallGenerator, MigrationGenerator, MissingConfiguration, Server, TokenInfoController, TokensController

Constant Summary collapse

VERSION =
'2.1.0'

Class Method Summary collapse

Class Method Details

.authenticate(request, methods = Doorkeeper.configuration.access_token_methods) ⇒ Object


68
69
70
# File 'lib/doorkeeper.rb', line 68

def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
  OAuth::Token.authenticate(request, *methods)
end

.check_for_missing_columnsObject


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/doorkeeper/config.rb', line 19

def self.check_for_missing_columns
  if Doorkeeper.configuration.orm == :active_record &&
      ActiveRecord::Base.connected? &&
      !Doorkeeper::Application.new.attributes.include?("scopes")

    puts "[doorkeeper] Missing column: `oauth_applications.scopes`.\nIf you are using ActiveRecord run `rails generate doorkeeper:application_scopes\n&& rake db:migrate` to add it.\n".squish
  end
end

.configurationObject


15
16
17
# File 'lib/doorkeeper/config.rb', line 15

def self.configuration
  @config || (fail MissingConfiguration.new)
end

.configure(&block) ⇒ Object


8
9
10
11
12
13
# File 'lib/doorkeeper/config.rb', line 8

def self.configure(&block)
  @config = Config::Builder.new(&block).build
  enable_orm
  check_for_missing_columns
  setup_application_owner if @config.enable_application_owner?
end

.configured?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'lib/doorkeeper.rb', line 56

def self.configured?
  @config.present?
end

.database_installed?Boolean

Returns:

  • (Boolean)

60
61
62
# File 'lib/doorkeeper.rb', line 60

def self.database_installed?
  [AccessToken, AccessGrant, Application].all? { |model| model.table_exists? }
end

.enable_ormObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/doorkeeper/config.rb', line 32

def self.enable_orm
  class_name = "doorkeeper/orm/#{configuration.orm}".classify
  class_name.constantize.initialize_models!
rescue NameError => e
  if e.instance_of?(NameError)
    fail e, "ORM adapter not found (#{configuration.orm})", "[doorkeeper] ORM adapter not found (\#{configuration.orm}), or there was an error\ntrying to load it.\n\nYou probably need to add the related gem for this adapter to work with\ndoorkeeper.\n\nIf you are working on the adapter itself, double check that the constant exists,\nand that your `initialize_models!` method doesn't raise any errors.\\n\n"
  else
    raise e
  end
end

.installed?Boolean

Returns:

  • (Boolean)

64
65
66
# File 'lib/doorkeeper.rb', line 64

def self.installed?
  configured? && database_installed?
end

.setup_application_ownerObject


52
53
54
55
# File 'lib/doorkeeper/config.rb', line 52

def self.setup_application_owner
  require File.join(File.dirname(__FILE__), 'models', 'concerns', 'ownership')
  Application.send :include, Models::Ownership
end