FEATURE: Allow steam authenticator to be revoked (#48)

Co-authored-by: Dmitry Antonov <chelog@octothorp.team>
This commit is contained in:
Alan Guo Xiang Tan 2022-05-09 10:20:30 +08:00 committed by GitHub
parent 4e87a2dc9c
commit a14b96c489
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -2,6 +2,7 @@ en:
site_settings:
enable_steam_logins: "Enable Steam authentication, requires steam_web_api_key. See <a href='https://meta.discourse.org/t/18153' target='_blank'>Steam Login / Authentication Plugin</a>"
steam_web_api_key: "Steam web API key"
steam_allow_revoke: "Allow users to unlink their Steam account"
errors:
steam_web_api_key_is_empty: "You must set 'steam web api key' before enabling this setting."

View File

@ -5,3 +5,5 @@ plugins:
steam_web_api_key:
default: ""
secret: true
steam_logins_allow_revoke:
default: false

View File

@ -9,6 +9,10 @@ class Auth::SteamAuthenticator < ::Auth::ManagedAuthenticator
SiteSetting.enable_steam_logins
end
def can_revoke?
SiteSetting.steam_logins_allow_revoke
end
def register_middleware(omniauth)
omniauth.provider :steam, setup: lambda { |env|
strategy = env["omniauth.strategy"]

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
describe Auth::SteamAuthenticator do
describe '#can_revoke?' do
it 'should be false be default' do
authenticator = Auth::SteamAuthenticator.new
expect(authenticator.can_revoke?).to eq(false)
end
it 'should be true when steam_logins_allow_revoke site settings is enabled' do
SiteSetting.steam_logins_allow_revoke = true
authenticator = Auth::SteamAuthenticator.new
expect(authenticator.can_revoke?).to eq(true)
end
end
end