# Creating extensions

In some cases you may want to have some functionality that extends Doorkeeper, but it's not something that is required by the OAuth RFC and must be implemented in gem itself. In such cases you may create an extension for Doorkeeper gem.

You can reuse Doorkeeper internals for your own purposes.

## Extension configuration

You can reuse Doorkeeper options DSL to define your own configurations.

```ruby
class YourExtension
  def self.configure(&block)
    @config = Config::Builder.new(Config.new, &block).build
  end

  def self.configuration
    @config || (raise Errors::MissingConfiguration)
  end

  class Config
    class Builder < Doorkeeper::Config::AbstractBuilder
      # your custom config methods
      def enforce_something
        @config.instance_variable_set(:@enforce_something, true)
      end
    end

    def enforce_something?
      if defined?(@enforce_something)
        @enforce_something
      else
        false
      end
    end

    # In case you defined some other builder class
    def self.builder_class
      Config::Builder
    end

    extend Doorkeeper::Config::Option

    # your custom options
    option :expiration_time, default: 1.hour
    option :skip_something, default: true
  end
end
```

Then your extension configuration will look like:

```ruby
# config/initializers/your_extension.rb
YourExtension.configure do
  expiration_time 15.minutes
  skip_something true

  enforce_something
end
```

Take a look at Doorkeeper config file to get more examples of options DSL and it's arguments.

## Examples

Examples of extensions in the wild:

* [doorkeeper-openid\_connect](https://github.com/doorkeeper-gem/doorkeeper-openid_connect/tree/master/lib/doorkeeper)
* [doorkeeper-sequel](https://github.com/nbulaj/doorkeeper-sequel)
* [doorkeeper-grants\_assertion](https://github.com/doorkeeper-gem/doorkeeper-grants_assertion)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doorkeeper.gitbook.io/guides/internals/creating-extensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
