DEV: Add verbose logging for google oauth (#29459)
Some checks failed
Tests / core frontend (${{ matrix.browser }}) (Chrome) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, plugins) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, themes) (push) Has been cancelled
Licenses / run (push) Has been cancelled
Linting / run (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (annotations, core) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, core) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (backend, plugins) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, plugins) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (frontend, themes) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, chat) (push) Has been cancelled
Tests / ${{ matrix.target }} ${{ matrix.build_type }} (system, core) (push) Has been cancelled
Tests / core frontend (${{ matrix.browser }}) (Firefox ESR) (push) Has been cancelled
Tests / core frontend (${{ matrix.browser }}) (Firefox Evergreen) (push) Has been cancelled

This commit is contained in:
Natalie Tay 2024-11-08 11:03:17 +08:00 committed by GitHub
parent 1d9f064d83
commit 6c36af9f62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 7 deletions

View File

@ -2006,6 +2006,7 @@ en:
google_oauth2_hd_groups: "Retrieve users' Google groups on the hosted domain on authentication. Retrieved Google groups can be used to grant automatic Discourse group membership (see group settings). For more information see https://meta.discourse.org/t/226850" google_oauth2_hd_groups: "Retrieve users' Google groups on the hosted domain on authentication. Retrieved Google groups can be used to grant automatic Discourse group membership (see group settings). For more information see https://meta.discourse.org/t/226850"
google_oauth2_hd_groups_service_account_admin_email: "An email address belonging to a Google Workspace administrator account. Will be used with the service account credentials to fetch group information." google_oauth2_hd_groups_service_account_admin_email: "An email address belonging to a Google Workspace administrator account. Will be used with the service account credentials to fetch group information."
google_oauth2_hd_groups_service_account_json: "JSON formatted key information for the Service Account. Will be used to fetch group information." google_oauth2_hd_groups_service_account_json: "JSON formatted key information for the Service Account. Will be used to fetch group information."
google_oauth2_verbose_logging: "Log verbose Google OAuth2 related diagnostics to <a href='%{base_path}/logs' target='_blank'>/logs</a>"
enable_twitter_logins: "Enable Twitter authentication, requires twitter_consumer_key and twitter_consumer_secret. See <a href='https://meta.discourse.org/t/13395' target='_blank'>Configuring Twitter login (and rich embeds) for Discourse</a>." enable_twitter_logins: "Enable Twitter authentication, requires twitter_consumer_key and twitter_consumer_secret. See <a href='https://meta.discourse.org/t/13395' target='_blank'>Configuring Twitter login (and rich embeds) for Discourse</a>."
twitter_consumer_key: "Consumer key for Twitter authentication, registered at <a href='https://developer.twitter.com/apps' target='_blank'>https://developer.twitter.com/apps</a>" twitter_consumer_key: "Consumer key for Twitter authentication, registered at <a href='https://developer.twitter.com/apps' target='_blank'>https://developer.twitter.com/apps</a>"

View File

@ -494,6 +494,8 @@ login:
google_oauth2_hd_groups_service_account_json: google_oauth2_hd_groups_service_account_json:
default: "" default: ""
textarea: true textarea: true
google_oauth2_verbose_logging:
default: false
enable_twitter_logins: enable_twitter_logins:
default: false default: false
twitter_consumer_key: twitter_consumer_key:

View File

@ -24,23 +24,31 @@ class Auth::GoogleOAuth2Authenticator < Auth::ManagedAuthenticator
options = { options = {
setup: setup:
lambda do |env| lambda do |env|
strategy = env["omniauth.strategy"] opts = env["omniauth.strategy"].options
strategy.options[:client_id] = SiteSetting.google_oauth2_client_id opts[:client_id] = SiteSetting.google_oauth2_client_id
strategy.options[:client_secret] = SiteSetting.google_oauth2_client_secret opts[:client_secret] = SiteSetting.google_oauth2_client_secret
if (google_oauth2_hd = SiteSetting.google_oauth2_hd).present? if (google_oauth2_hd = SiteSetting.google_oauth2_hd).present?
strategy.options[:hd] = google_oauth2_hd opts[:hd] = google_oauth2_hd
end end
if (google_oauth2_prompt = SiteSetting.google_oauth2_prompt).present? if (google_oauth2_prompt = SiteSetting.google_oauth2_prompt).present?
strategy.options[:prompt] = google_oauth2_prompt.gsub("|", " ") opts[:prompt] = google_oauth2_prompt.gsub("|", " ")
end
opts[:client_options][:connection_build] = lambda do |builder|
if SiteSetting.google_oauth2_verbose_logging
builder.response :logger,
Rails.logger,
{ bodies: true, formatter: Auth::OauthFaradayFormatter }
end
builder.request :url_encoded
builder.adapter FinalDestination::FaradayAdapter
end end
# All the data we need for the `info` and `credentials` auth hash # All the data we need for the `info` and `credentials` auth hash
# are obtained via the user info API, not the JWT. Using and verifying # are obtained via the user info API, not the JWT. Using and verifying
# the JWT can fail due to clock skew, so let's skip it completely. # the JWT can fail due to clock skew, so let's skip it completely.
# https://github.com/zquestz/omniauth-google-oauth2/pull/392 # https://github.com/zquestz/omniauth-google-oauth2/pull/392
strategy.options[:skip_jwt] = true opts[:skip_jwt] = true
end, end,
} }
omniauth.provider :google_oauth2, options omniauth.provider :google_oauth2, options