-
Notifications
You must be signed in to change notification settings - Fork 5.5k
add support for multiple omniauthable models #5176
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
base: main
Are you sure you want to change the base?
Conversation
|
Hello, @john-denisov! This is your first Pull Request that will be reviewed by SourceLevel, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information. |
| raise "Wrong OmniAuth configuration. If you are getting this exception, it means that either:\n\n" \ | ||
| "1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one\n" \ | ||
| "2) You are setting :omniauthable in more than one model\n" \ | ||
| "2) You are setting :omniauthable in more than one model, but you did not specify custom path_prefix " \ |
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.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
|
SourceLevel has finished reviewing this Pull Request and has found:
|
|
+1 for this one @ivan-denysov . Can I help in anyway to move this forward? |
|
@ivan-denysov: This current setup doesn't quite cover the possible situations thoroughly. Firstly, you might have more providers defined on the model than in the configuration (if you use the Secondly, you might have an additional provider defined in addition to the provider used on multiple models. In that case, you will likely have a configuration without a Thirdly, you might have multiple providers used by multiple models. Given these possibilities, I think the better articulation of the desired logic is:
Here is my attempt to capture this logic: single_provider_with_multiple_configs = Devise.omniauth_configs.group_by { |_,config| config.provider }.select { |_,configs| configs.count > 1 }
all_configs_for_each_provider_with_multiple_configs_has_path_prefix_set = single_provider_with_multiple_configs.all? { |_,configs| configs.all? { |_, config| config.options[:path_prefix].present? } }
if single_provider_with_multiple_configs.empty? || !all_configs_for_each_provider_with_multiple_configs_has_path_prefix_set
set_omniauth_path_prefix!(path_prefix)
end |
AFAIK
devisedoesn't support omniauthable for multiple models because long time agoomniauthdid not support custom path_prefix for each strategy. But according to this comment from @josevalim omniauth solved that issue at least 9 years ago.I implemented a sample rails application that shows how omniauthable can be used for multiple devise models.
main commit of that app: ivandenysov/showcase-multiple-omniauthable-models@7b1f237
installation instructions: https://github.com/john-denisov/showcase-multiple-omniauthable-models/blob/master/README.md
I followed this guide to implement omniauth sign in for users and managers in my demo app
I will also update https://github.com/plataformatec/devise/wiki/OmniAuth-with-multiple-models if this PR gets approved
Will appreciate any ideas how to improve this feature. Theoretically we can automatically duplicate all registered providers and set correct
path_prefixfor them ifdevise :omniauthableis specified in more than 1 model. That will reduce amount of configuration required but it won't allow to have separate sets of providers for different models 🤔Or we could also add new arg toDevise.omniauthcalledscopes:. Default would be to add this strategy to all omniauthable scopes.