-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy evaluate Doorkeeper config when loading files and executing initializers #1627
Conversation
c27b7ef
to
0ba7896
Compare
lib/doorkeeper/engine.rb
Outdated
parameters = %w[client_secret authentication_token access_token refresh_token] | ||
parameters << "code" if Doorkeeper.config.grant_flows.include?("authorization_code") | ||
app.config.filter_parameters << /^(#{Regexp.union(parameters)})$/ | ||
initializer "doorkeeper.params.filter", after: :load_config_initializers do |app| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double whitespace before do
here
lib/doorkeeper/config.rb
Outdated
@@ -33,6 +35,10 @@ def configuration | |||
@config || (raise MissingConfiguration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line still raises an error.
d361df7
to
8838264
Compare
8e907d9
to
1e0a796
Compare
This broke my initializer in development (I haven't tested in production):
I have in my initializer/config: Doorkeeper.configure do
# ...
access_token_class 'DoorkeeperAccessToken'
# ...
end Rails v7.0.4.2 |
Yeah, can I see your |
It's a regular rails model in class DoorkeeperAccessToken < ApplicationRecord
include ::Doorkeeper::Orm::ActiveRecord::Mixins::AccessToken
after_save :sync_legacy_token
private
def sync_legacy_token
#
end
end Downgrading to v5.6.2 works. |
@zavan could you please try with |
It works 😄 |
Root of the issue is the fact that Rails or some specific gems (like Sorbet) could load model files before initializers have been run. Since some models have constructions like:
in their class body - it will trigger an error because
@config
still doesn't exist (Doorkeeper.configure
block wasn't called).The same is applied to Doorkeeper railtie (engine): it adds some custom parameters filters based on the OAuth configuration, but it does it even for the new Rails apps which have not yet generated an initializer (just added a gem and run
rails g doorkeeper:install
).What should be done:
Addresses:
rails generate doorkeeper:install
fails withDoorkeeper::MissingConfiguration
error #1617