discourse-steam-login/plugin.rb

76 lines
1.8 KiB
Ruby
Raw Normal View History

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
# author: J. de Faye
# template author: S. Saffron
2014-07-20 15:01:34 -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
result.username = data["nickname"]
result.name = data["name"] # unless profile privacy set to private
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]
::PluginStore.set('steam', "steam_uid_#{data[:steam_uid]}", {user_id: user.id })
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 {
background: #000;
2014-07-20 15:01:34 -04:00
}
.btn-social.steam:before {
content: $fa-var-steam;
2014-07-20 15:01:34 -04:00
}
CSS