diff --git a/.env_sample b/.env_sample index 615574c08..a1f7a124b 100644 --- a/.env_sample +++ b/.env_sample @@ -32,23 +32,6 @@ export ELASTICSEARCH_URL="http://localhost:9200" # SSL config export FORCE_SSL_IN_RAILS="not applicable in dev" -################################################ -############## 3rd Party Services ############## -################################################ - -# It's best if you have the following configured -# for more development experience - -# GitHub -# (https://developer.github.com/v3/guides/basics-of-authentication/) -export GITHUB_KEY="" -export GITHUB_SECRET="" - -# Twitter -# (https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0/application-only) -export TWITTER_KEY="" -export TWITTER_SECRET="" - ################################################ ######### Optional 3rd Party Services ########## ################################################ diff --git a/app/controllers/admin/configs_controller.rb b/app/controllers/admin/configs_controller.rb index 57aea9412..39a5639a2 100644 --- a/app/controllers/admin/configs_controller.rb +++ b/app/controllers/admin/configs_controller.rb @@ -39,6 +39,10 @@ module Admin default_font sponsor_headline public + twitter_key + twitter_secret + github_key + github_secret ] allowed_params = allowed_params | diff --git a/app/lib/constants/site_config.rb b/app/lib/constants/site_config.rb index 9ef1eda1b..62407f788 100644 --- a/app/lib/constants/site_config.rb +++ b/app/lib/constants/site_config.rb @@ -87,6 +87,14 @@ module Constants description: "Determines which default feed the users sees (rich content, more minimal, etc.)", placeholder: "basic, rich, or compact" }, + github_key: { + description: "The \"Client ID\" portion of the GitHub Oauth Apps portal", + placeholder: "" + }, + github_secret: { + description: "The \"Client Secret\" portion of the GitHub Oauth Apps portal", + placeholder: "" + }, ga_view_id: { description: "Google Analytics Reporting API v4 - View ID", placeholder: "" @@ -228,6 +236,14 @@ module Constants twitter_hashtag: { description: "Used as the twitter hashtag of the community", placeholder: "#DEVCommunity" + }, + twitter_key: { + description: "The \"API key\" portion of consumer keys in the Twitter developer portal.", + placeholder: "" + }, + twitter_secret: { + description: "The \"API secret key\" portion of consumer keys in the Twitter developer portal.", + placeholder: "" } # Dynamic values ommitted: configurable_rate_limits and social_media_handles }.freeze diff --git a/app/models/site_config.rb b/app/models/site_config.rb index 497499e27..9bccdd897 100644 --- a/app/models/site_config.rb +++ b/app/models/site_config.rb @@ -16,6 +16,10 @@ class SiteConfig < RailsSettings::Base # Authentication field :authentication_providers, type: :array, default: Authentication::Providers.available + field :twitter_key, type: :string, default: ApplicationConfig["TWITTER_KEY"] + field :twitter_secret, type: :string, default: ApplicationConfig["TWITTER_SECRET"] + field :github_key, type: :string, default: ApplicationConfig["GITHUB_KEY"] + field :github_secret, type: :string, default: ApplicationConfig["GITHUB_SECRET"] # Campaign field :campaign_hero_html_variant_name, type: :string, default: "" diff --git a/app/views/admin/configs/show.html.erb b/app/views/admin/configs/show.html.erb index 15e1f0882..10ab03f9a 100644 --- a/app/views/admin/configs/show.html.erb +++ b/app/views/admin/configs/show.html.erb @@ -130,9 +130,41 @@ class: "form-control selectpicker" %>
<%= Constants::SiteConfig::DETAILS[:authentication_providers][:description] %>
+

Notice: Changing authentication keys will not take affect until devops restarts the app (about once per day). This will soon be instant.

+
+ <%= admin_config_label :twitter_key %> + <%= f.text_field :twitter_key, + class: "form-control", + value: SiteConfig.twitter_key, + placeholder: Constants::SiteConfig::DETAILS[:twitter_key][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:twitter_key][:description] %>
+
+
+ <%= admin_config_label :twitter_secret %> + <%= f.text_field :twitter_secret, + class: "form-control", + value: SiteConfig.twitter_secret, + placeholder: Constants::SiteConfig::DETAILS[:twitter_secret][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:twitter_secret][:description] %>
+
+
+ <%= admin_config_label :github_key %> + <%= f.text_field :github_key, + class: "form-control", + value: SiteConfig.github_key, + placeholder: Constants::SiteConfig::DETAILS[:github_key][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:github_key][:description] %>
+
+
+ <%= admin_config_label :github_secret %> + <%= f.text_field :github_secret, + class: "form-control", + value: SiteConfig.github_secret, + placeholder: Constants::SiteConfig::DETAILS[:github_secret][:placeholder] %> +
<%= Constants::SiteConfig::DETAILS[:github_secret][:description] %>
+
-
<%= render partial: "card_header", locals: { diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 2bfe63f54..f5cb81706 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,5 +1,14 @@ -# Use this hook to configure devise mailer, warden hooks and so forth. -# Many of these configuration options can be set straight in your model. +TWITTER_OMNIAUTH_SETUP = lambda do |env| + env["omniauth.strategy"].options[:consumer_key] = SiteConfig.twitter_key + env["omniauth.strategy"].options[:consumer_secret] = SiteConfig.twitter_secret +end + +GITHUB_OMNIUATH_SETUP = lambda do |env| + env["omniauth.strategy"].options[:client_id] = SiteConfig.github_key + env["omniauth.strategy"].options[:client_secret] = SiteConfig.github_secret + env["omniauth.strategy"].options[:scope] = "user:email" +end + Devise.setup do |config| # The secret key used by Devise. Devise uses this key to generate # random tokens. Changing this key will render invalid all existing @@ -283,9 +292,10 @@ Devise.setup do |config| # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. - # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' - config.omniauth :github, ApplicationConfig["GITHUB_KEY"], ApplicationConfig["GITHUB_SECRET"], scope: "user:email" - config.omniauth :twitter, ApplicationConfig["TWITTER_KEY"], ApplicationConfig["TWITTER_SECRET"] + + # Fun fact, if this is reordered to have Twitter first, it doesn't work for some reason. + config.omniauth :github, setup: GITHUB_OMNIUATH_SETUP + config.omniauth :twitter, setup: TWITTER_OMNIAUTH_SETUP # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/docs/getting-started/config-env.md b/docs/getting-started/config-env.md index 1f402ddee..e9a3a1252 100644 --- a/docs/getting-started/config-env.md +++ b/docs/getting-started/config-env.md @@ -22,8 +22,9 @@ Then, add each key you need to the `.env` file. For example, if you're setting up GitHub authentication: ```shell -export GITHUB_KEY="SOME_REAL_SECURE_KEY_HERE" -export GITHUB_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" +export CLOUDINARY_API_KEY="SOME_REAL_SECURE_KEY_HERE" +export CLOUDINARY_API_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" +export CLOUDINARY_CLOUD_NAME="A_CLOUDINARY_NAME" ``` (Don't worry, your `.env` file is ignored by git) diff --git a/docs/installation/containers.md b/docs/installation/containers.md index e956ff920..ba03d6fa8 100644 --- a/docs/installation/containers.md +++ b/docs/installation/containers.md @@ -73,8 +73,9 @@ with Podman. You can install it by following these enter/replace. i.e.: ```shell - export GITHUB_KEY="SOME_REAL_SECURE_KEY_HERE" - export GITHUB_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" + export CLOUDINARY_API_KEY="SOME_REAL_SECURE_KEY_HERE" + export CLOUDINARY_API_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" + export CLOUDINARY_CLOUD_NAME="A_CLOUDINARY_NAME" ``` - You do not need "real" keys for basic development. Some features require diff --git a/docs/installation/linux.md b/docs/installation/linux.md index 8be5d9a96..2c36d7a07 100644 --- a/docs/installation/linux.md +++ b/docs/installation/linux.md @@ -103,8 +103,9 @@ NOTE: Make sure to download **the OSS version**, `elasticsearch-oss`. enter/replace. i.e.: ```shell - export GITHUB_KEY="SOME_REAL_SECURE_KEY_HERE" - export GITHUB_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" + export CLOUDINARY_API_KEY="SOME_REAL_SECURE_KEY_HERE" + export CLOUDINARY_API_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" + export CLOUDINARY_CLOUD_NAME="A_CLOUDINARY_NAME" ``` - If you are missing `ENV` variables on bootup, the diff --git a/docs/installation/mac.md b/docs/installation/mac.md index 443845d5d..9eee0f92f 100644 --- a/docs/installation/mac.md +++ b/docs/installation/mac.md @@ -223,8 +223,9 @@ your local Elasticsearch installation, for example: enter/replace. i.e.: ```shell - export GITHUB_KEY="SOME_REAL_SECURE_KEY_HERE" - export GITHUB_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" + export CLOUDINARY_API_KEY="SOME_REAL_SECURE_KEY_HERE" + export CLOUDINARY_API_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" + export CLOUDINARY_CLOUD_NAME="A_CLOUDINARY_NAME" ``` - If you are missing `ENV` variables on bootup, the