moduleDoorkeeperclassMissingConfiguration<StandardError# Defines a MissingConfiguration error for a missing Doorkeeper# configurationdefinitializesuper('Configuration for doorkeeper missing. Do you have doorkeeper initializer?')endenddefself.configure(&block)@config=Config::Builder.new(&block).buildsetup_orm_adaptersetup_orm_modelssetup_application_ownerif@config.enable_application_owner?enddefself.configuration@config||(failMissingConfiguration)enddefself.setup_orm_adapter@orm_adapter="doorkeeper/orm/#{configuration.orm}".classify.constantizerescueNameError=>efaile,"ORM adapter not found (#{configuration.orm})",<<-ERROR_MSG.squish
[doorkeeper] ORM adapter not found (#{configuration.orm}), or there was an error
trying to load it.
You probably need to add the related gem for this adapter to work with
doorkeeper.
ERROR_MSGenddefself.setup_orm_models@orm_adapter.initialize_models!enddefself.setup_application_owner@orm_adapter.initialize_application_owner!endclassConfigclassBuilderdefinitialize(&block)@config=Config.newinstance_eval(&block)enddefbuild@configend# Provide support for an owner to be assigned to each registered# application (disabled by default)# Optional parameter confirmation: true (default false) if you want# to enforce ownership of a registered application## @param opts [Hash] the options to confirm if an application owner# is present# @option opts[Boolean] :confirmation (false)# Set confirm_application_owner variabledefenable_application_owner(opts={})@config.instance_variable_set('@enable_application_owner',true)confirm_application_ownerifopts[:confirmation].present?&&opts[:confirmation]enddefconfirm_application_owner@config.instance_variable_set('@confirm_application_owner',true)end# Define default access token scopes for your provider## @param scopes [Array] Default set of access (OAuth::Scopes.new)# token scopesdefdefault_scopes(*scopes)@config.instance_variable_set('@default_scopes',OAuth::Scopes.from_array(scopes))end# Define default access token scopes for your provider## @param scopes [Array] Optional set of access (OAuth::Scopes.new)# token scopesdefoptional_scopes(*scopes)@config.instance_variable_set('@optional_scopes',OAuth::Scopes.from_array(scopes))end# Change the way client credentials are retrieved from the request object.# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then# falls back to the `:client_id` and `:client_secret` params from the# `params` object.## @param methods [Array] Define client credentialsdefclient_credentials(*methods)@config.instance_variable_set('@client_credentials',methods)end# Change the way access token is authenticated from the request object.# By default it retrieves first from the `HTTP_AUTHORIZATION` header, then# falls back to the `:access_token` or `:bearer_token` params from the# `params` object.## @param methods [Array] Define access token methodsdefaccess_token_methods(*methods)@config.instance_variable_set('@access_token_methods',methods)end# Issue access tokens with refresh token (disabled by default)defuse_refresh_token@config.instance_variable_set('@refresh_token_enabled',true)end# WWW-Authenticate Realm (default "Doorkeeper").## @param realm [String] ("Doorkeeper") Authentication realmdefrealm(realm)@config.instance_variable_set('@realm',realm)end# Reuse access token for the same resource owner within an application# (disabled by default)# Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383defreuse_access_token@config.instance_variable_set("@reuse_access_token",true)end# Forces the usage of the HTTPS protocol in non-native redirect uris# (enabled by default in non-development environments). OAuth2# delegates security in communication to the HTTPS protocol so it is# wise to keep this enabled.## @param [Boolean] boolean value for the parameter, true by default in# non-development environmentdefforce_ssl_in_redirect_uri(boolean)@config.instance_variable_set("@force_ssl_in_redirect_uri",boolean)end# Use a custom class for generating the access token.# https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator## @param access_token_generator [String]# the name of the access token generator classdefaccess_token_generator(access_token_generator)@config.instance_variable_set('@access_token_generator',access_token_generator)end# The controller Doorkeeper::ApplicationController inherits from.# Defaults to ActionController::Base.# https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller## @param base_controller [String] the name of the base controllerdefbase_controller(base_controller)@config.instance_variable_set('@base_controller',base_controller)endendmoduleOption# Defines configuration option## When you call option, it defines two methods. One method will take place# in the +Config+ class and the other method will take place in the# +Builder+ class.## The +name+ parameter will set both builder method and config attribute.# If the +:as+ option is defined, the builder method will be the specified# option while the config attribute will be the +name+ parameter.## If you want to introduce another level of config DSL you can# define +builder_class+ parameter.# Builder should take a block as the initializer parameter and respond to function +build+# that returns the value of the config attribute.## ==== Options## * [:+as+] Set the builder method that goes inside +configure+ block# * [+:default+] The default value in case no option was set## ==== Examples## option :name# option :name, as: :set_name# option :name, default: 'My Name'# option :scopes builder_class: ScopesBuilder#defoption(name,options={})attribute=options[:as]||nameattribute_builder=options[:builder_class]Builder.instance_evaldoremove_methodnameifmethod_defined?(name)define_methodnamedo|*args,&block|# TODO: is builder_class option being used?value=ifattribute_builderattribute_builder.new(&block).buildelseblock?block:args.firstend@config.instance_variable_set(:"@#{attribute}",value)endenddefine_methodattributedo|*_args|ifinstance_variable_defined?(:"@#{attribute}")instance_variable_get(:"@#{attribute}")elseoptions[:default]endendpublicattributeenddefextended(base)base.send(:private,:option)endendextendOptionoption:resource_owner_authenticator,as: :authenticate_resource_owner,default: (lambdado|_routes|logger.warn(I18n.translate('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))nilend)option:admin_authenticator,as: :authenticate_admin,default: ->(_routes){}option:resource_owner_from_credentials,default: (lambdado|_routes|warn(I18n.translate('doorkeeper.errors.messages.credential_flow_not_configured'))nilend)option:skip_authorization,default: ->(_routes){}option:access_token_expires_in,default: 7200option:custom_access_token_expires_in,default: ->(_app){nil}option:authorization_code_expires_in,default: 600option:orm,default: :active_recordoption:native_redirect_uri,default: 'urn:ietf:wg:oauth:2.0:oob'option:active_record_options,default: {}option:realm,default: 'Doorkeeper'option:force_ssl_in_redirect_uri,default: !Rails.env.development?option:grant_flows,default: %w(authorization_code client_credentials)option:access_token_generator,default: 'Doorkeeper::OAuth::Helpers::UniqueToken'option:base_controller,default: 'ActionController::Base'attr_reader:reuse_access_tokendefrefresh_token_enabled?@refresh_token_enabled||=false!!@refresh_token_enabledenddefenable_application_owner?@enable_application_owner||=false!!@enable_application_ownerenddefconfirm_application_owner?@confirm_application_owner||=false!!@confirm_application_ownerenddefdefault_scopes@default_scopes||=OAuth::Scopes.newenddefoptional_scopes@optional_scopes||=OAuth::Scopes.newenddefscopes@scopes||=default_scopes+optional_scopesenddefclient_credentials_methods@client_credentials||=[:from_basic,:from_params]enddefaccess_token_methods@access_token_methods||=[:from_bearer_authorization,:from_access_token_param,:from_bearer_param]enddefauthorization_response_types@authorization_response_types||=calculate_authorization_response_typesenddeftoken_grant_types@token_grant_types||=calculate_token_grant_typesendprivate# Determines what values are acceptable for 'response_type' param in# authorization request endpoint, and return them as an array of strings.#defcalculate_authorization_response_typestypes=[]types<<'code'ifgrant_flows.include?'authorization_code'types<<'token'ifgrant_flows.include?'implicit'typesend# Determines what values are acceptable for 'grant_type' param token# request endpoint, and return them in array.#defcalculate_token_grant_typestypes=grant_flows-['implicit']types<<'refresh_token'ifrefresh_token_enabled?typesendendend