mirror of
https://github.com/discourse/discourse-steam-login.git
synced 2025-02-16 16:34:53 +00:00
Update plugin inline with new plugin format
NOTICE: do not use this in production register_middleware cannot retrieve 'api_key This cannot come out of experimental until fixed
This commit is contained in:
parent
491a3682a2
commit
4117f64e2e
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
auto_generated/
|
@ -17,9 +17,9 @@ Discourse Steam Login
|
||||
|
||||
5. Run `./launcher rebuild app` to apply the changes.
|
||||
|
||||
6. You're done! Please consider starring [my repository][1] as it gives me some feedback on whether this is well received. This will encourage me to find more time to improve the plugin and enhance it in the future.
|
||||
6. You're done! Please consider starring [my repository][1] if you use github. The more attention it gets, the more I will give back to it.
|
||||
|
||||
7. If you encounter problems, or know 100% that it is a bug with the plugin, make a report here, and include full details, screenshots, and sensored configuration of your `app.yml`. Go into precise details into how to reproduce the problem. Do not write bug reports if you do not have the time to write a proper report or can be bothered to investigate the issue methodically yourself first. For community help, head over to the [meta.discourse.org page][2].
|
||||
7. Please ask well-formed, well-written questions at the [meta.discourse.org page][2]. If you think there is a bug, then go to some effort to prove it if you intend to open an issue, or I will not take you seriously.
|
||||
|
||||
[1]:https://github.com/defaye/discourse-steam-login
|
||||
[2]:https://meta.discourse.org/t/steam-login-authentication-plugin/18153
|
||||
|
6
assets/stylesheets/plugin.scss
Normal file
6
assets/stylesheets/plugin.scss
Normal file
@ -0,0 +1,6 @@
|
||||
.btn-social.steam {
|
||||
background: #000;
|
||||
&::before {
|
||||
content: $fa-var-steam;
|
||||
}
|
||||
}
|
4
config/locales/server.en.yml
Normal file
4
config/locales/server.en.yml
Normal file
@ -0,0 +1,4 @@
|
||||
en:
|
||||
site_settings:
|
||||
discourse_steam_login_enabled: "Allow users to authenticate via Steam?"
|
||||
discourse_steam_login_api_key: "Available from <a href=\"http://steamcommunity.com/dev/apikey\" target=\"_blank\">steamcommunity.com/dev/apikey</a> e.g. forum.example.org"
|
7
config/settings.yml
Normal file
7
config/settings.yml
Normal file
@ -0,0 +1,7 @@
|
||||
plugins:
|
||||
discourse_steam_login_enabled:
|
||||
client: true
|
||||
default: false
|
||||
discourse_steam_login_api_key:
|
||||
client: false
|
||||
default: ''
|
@ -1,8 +1,3 @@
|
||||
# name: omniauth-steam
|
||||
# about: omniauth-steam
|
||||
# version: 1.0.3
|
||||
# author: Rodrigo Navarro
|
||||
|
||||
require 'omniauth-openid'
|
||||
require 'multi_json'
|
||||
|
||||
@ -18,6 +13,7 @@ module OmniAuth
|
||||
uid { steam_id }
|
||||
|
||||
info do
|
||||
begin
|
||||
{
|
||||
"nickname" => player["personaname"],
|
||||
"name" => player["realname"],
|
||||
@ -28,20 +24,29 @@ module OmniAuth
|
||||
"FriendList" => friend_list_url
|
||||
}
|
||||
}
|
||||
rescue MultiJson::ParseError => exception
|
||||
fail!(:steamError, exception)
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
extra do
|
||||
{ "raw_info" => player }
|
||||
begin
|
||||
{ "raw_info" => player }
|
||||
rescue MultiJson::ParseError => exception
|
||||
fail!(:steamError, exception)
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def raw_info
|
||||
@raw_info ||= options.api_key ? MultiJson.decode(Net::HTTP.get(player_profile_uri)) : {}
|
||||
@raw_info ||= options.api_key ? MultiJson.decode(Net::HTTP.get(player_profile_uri)) : {}
|
||||
end
|
||||
|
||||
def player
|
||||
@player ||= raw_info["response"]["players"].first
|
||||
@player ||= raw_info["response"]["players"].first
|
||||
end
|
||||
|
||||
def steam_id
|
59
plugin.rb
59
plugin.rb
@ -1,17 +1,31 @@
|
||||
# name: Steam authentication with Discourse
|
||||
# about: Authenticate with Discourse with Steam
|
||||
# version: 1.1.1
|
||||
# author: J. de Faye
|
||||
# template author: S. Saffron
|
||||
# name: Steam authenticator
|
||||
# about: Authenticate with Discourse via Steam
|
||||
# version: 1.2
|
||||
# author: Jonathan de Faye
|
||||
# url: https://github.com/defaye/discourse-steam-login
|
||||
|
||||
require File.expand_path('../omniauth-steam.rb', __FILE__)
|
||||
enabled_site_setting :discourse_steam_login_enabled
|
||||
enabled_site_setting :discourse_steam_login_api_key
|
||||
|
||||
require File.expand_path('../lib/omniauth-steam.rb', __FILE__)
|
||||
|
||||
register_asset 'stylesheets/plugin.scss'
|
||||
|
||||
class SteamAuthenticator < ::Auth::Authenticator
|
||||
|
||||
def name
|
||||
'steam'
|
||||
end
|
||||
|
||||
def register_middleware(omniauth)
|
||||
omniauth.provider :steam, SiteSetting.discourse_steam_login_api_key.present? ?
|
||||
SiteSetting.discourse_steam_login_api_key : ENV['STEAM_WEB_API_KEY']
|
||||
end
|
||||
|
||||
def after_create_account(user, auth)
|
||||
data = auth[:extra_data]
|
||||
::PluginStore.set('steam', "steam_uid_#{data[:steam_uid]}", {user_id: user.id })
|
||||
end
|
||||
|
||||
def after_authenticate(auth_token)
|
||||
result = Auth::Result.new
|
||||
|
||||
@ -32,32 +46,9 @@ class SteamAuthenticator < ::Auth::Authenticator
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def after_create_account(user, auth)
|
||||
data = auth[:extra_data]
|
||||
::PluginStore.set('steam', "steam_uid_#{data[:steam_uid]}", {user_id: user.id })
|
||||
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;
|
||||
}
|
||||
|
||||
.btn-social.steam:before {
|
||||
content: $fa-var-steam;
|
||||
}
|
||||
|
||||
CSS
|
||||
auth_provider authenticator: SteamAuthenticator.new,
|
||||
title: 'with Steam',
|
||||
frame_width: 960,
|
||||
frame_height: 800
|
||||
|
Loading…
x
Reference in New Issue
Block a user