2014-07-20 15:01:34 -04:00
|
|
|
# name: Steam authentication with Discourse
|
|
|
|
# about: Authenticate with Discourse with Steam
|
2015-08-05 15:16:11 -04:00
|
|
|
# version: 1.1.1
|
2015-06-13 16:36:04 -04:00
|
|
|
# author: J. de Faye
|
|
|
|
# template author: S. Saffron
|
2014-07-20 15:01:34 -04:00
|
|
|
|
2014-07-27 13:57:20 -04:00
|
|
|
require File.expand_path('../omniauth-steam.rb', __FILE__)
|
2014-07-20 15:01:34 -04:00
|
|
|
|
|
|
|
class SteamAuthenticator < ::Auth::Authenticator
|
|
|
|
|
|
|
|
def name
|
|
|
|
'steam'
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_authenticate(auth_token)
|
|
|
|
result = Auth::Result.new
|
|
|
|
|
|
|
|
data = auth_token[:info]
|
|
|
|
raw_info = auth_token["extra"]["raw_info"]
|
|
|
|
steam_uid = auth_token["uid"]
|
|
|
|
|
|
|
|
current_info = ::PluginStore.get('steam', "steam_uid_#{steam_uid}")
|
|
|
|
|
|
|
|
result.user =
|
|
|
|
if current_info
|
|
|
|
User.where(id: current_info[:user_id]).first
|
|
|
|
end
|
|
|
|
|
2015-06-13 16:36:04 -04:00
|
|
|
result.username = data["nickname"]
|
|
|
|
result.name = data["name"] # unless profile privacy set to private
|
2017-01-19 22:34:48 -05:00
|
|
|
result.extra_data = { steam_uid: steam_uid, image: data["image"] }
|
2014-07-20 15:01:34 -04:00
|
|
|
|
2016-11-19 10:28:47 -05:00
|
|
|
retrieve_avatar(result.user, data["image"])
|
|
|
|
|
2014-07-20 15:01:34 -04:00
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2016-11-19 10:28:47 -05:00
|
|
|
def retrieve_avatar(user, image_url)
|
|
|
|
return unless user
|
|
|
|
return unless image_url
|
|
|
|
return if user.user_avatar.try(:custom_upload_id).present?
|
|
|
|
|
|
|
|
Jobs.enqueue(:download_avatar_from_url, url: image_url, user_id: user.id, override_gravatar: true)
|
|
|
|
end
|
|
|
|
|
2014-07-20 15:01:34 -04:00
|
|
|
def after_create_account(user, auth)
|
|
|
|
data = auth[:extra_data]
|
2015-06-13 16:36:04 -04:00
|
|
|
::PluginStore.set('steam', "steam_uid_#{data[:steam_uid]}", {user_id: user.id })
|
2017-01-19 22:34:48 -05:00
|
|
|
|
|
|
|
retrieve_avatar(user, data[:image])
|
2014-07-20 15:01:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def register_middleware(omniauth)
|
|
|
|
omniauth.provider :steam, ENV['STEAM_WEB_API_KEY']
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
auth_provider title: 'with Steam',
|
|
|
|
message: 'Sign in via Steam (Make sure pop up blockers are not enabled).',
|
|
|
|
frame_width: 960,
|
|
|
|
frame_height: 800,
|
|
|
|
authenticator: SteamAuthenticator.new
|
|
|
|
|
|
|
|
register_css <<CSS
|
|
|
|
|
|
|
|
.btn-social.steam {
|
2015-07-24 16:16:25 -04:00
|
|
|
background: #000;
|
2014-07-20 15:01:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.btn-social.steam:before {
|
2015-08-05 12:47:32 -04:00
|
|
|
content: $fa-var-steam;
|
2014-07-20 15:01:34 -04:00
|
|
|
}
|
|
|
|
|
2015-08-05 12:47:32 -04:00
|
|
|
CSS
|