mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-22 22:36:11 +08:00
This adds a link for each authentication providers that are listed in /my/preferences/account in the "Associated Accounts" section. This is particularly useful when Discourse is being used in the PWA or in the DiscourseMobile app where there's no browser bar available and the only way to visit the provider's website is to open a browser window. That way, they can _just_ click the provider's name. Internal ref - t/156255 --- **BEFORE**  **AFTER** 
66 lines
1.7 KiB
Ruby
Vendored
66 lines
1.7 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class Auth::DiscourseIdAuthenticator < Auth::ManagedAuthenticator
|
|
class DiscourseIdStrategy < ::OmniAuth::Strategies::OAuth2
|
|
option :name, "discourse_id"
|
|
|
|
option :client_options, auth_scheme: :basic_auth
|
|
|
|
def authorize_params
|
|
super.tap { _1[:intent] = "signup" if request.params["signup"] == "true" }
|
|
end
|
|
|
|
def callback_url
|
|
Discourse.base_url_no_prefix + callback_path
|
|
end
|
|
|
|
uid { access_token.params["info"]["uuid"] }
|
|
|
|
info do
|
|
{
|
|
nickname: access_token.params["info"]["username"],
|
|
email: access_token.params["info"]["email"],
|
|
image: access_token.params["info"]["image"],
|
|
}
|
|
end
|
|
end
|
|
|
|
def name
|
|
"discourse_id"
|
|
end
|
|
|
|
def display_name
|
|
"Discourse ID"
|
|
end
|
|
|
|
def provider_url
|
|
site
|
|
end
|
|
|
|
def enabled?
|
|
SiteSetting.enable_discourse_id && SiteSetting.discourse_id_client_id.present? &&
|
|
SiteSetting.discourse_id_client_secret.present?
|
|
end
|
|
|
|
def site
|
|
SiteSetting.discourse_id_provider_url.presence || "https://id.discourse.com"
|
|
end
|
|
|
|
def register_middleware(omniauth)
|
|
omniauth.provider DiscourseIdStrategy,
|
|
scope: "read",
|
|
setup: ->(env) do
|
|
env["omniauth.strategy"].options.merge!(
|
|
client_id: SiteSetting.discourse_id_client_id,
|
|
client_secret: SiteSetting.discourse_id_client_secret,
|
|
client_options: {
|
|
site:,
|
|
},
|
|
)
|
|
end
|
|
end
|
|
|
|
def primary_email_verified?(auth_token)
|
|
true # email will be verified at source
|
|
end
|
|
end
|