doorkeeper
Search…
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.
1
class YourExtension
2
def self.configure(&block)
3
@config = Config::Builder.new(Config.new, &block).build
4
end
5
6
def self.configuration
7
@config || (raise Errors::MissingConfiguration)
8
end
9
10
class Config
11
class Builder < Doorkeeper::Config::AbstractBuilder
12
# your custom config methods
13
def enforce_something
14
@config.instance_variable_set(:@enforce_something, true)
15
end
16
end
17
18
def enforce_something?
19
if defined?(@enforce_something)
20
@enforce_something
21
else
22
false
23
end
24
end
25
26
# In case you defined some other builder class
27
def self.builder_class
28
Config::Builder
29
end
30
31
extend Doorkeeper::Config::Option
32
33
# your custom options
34
option :expiration_time, default: 1.hour
35
option :skip_something, default: true
36
end
37
end
Copied!
Then your extension configuration will look like:
1
# config/initializers/your_extension.rb
2
YourExtension.configure do
3
expiration_time 15.minutes
4
skip_something true
5
6
enforce_something
7
end
Copied!
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:
Last modified 1yr ago