Release v2.0.0 of Steam plugin.
This commit is contained in:
parent
d92537e85d
commit
76afc34425
26
README.md
26
README.md
|
@ -1,25 +1 @@
|
||||||
Discourse Steam Login
|
https://meta.discourse.org/t/steam-login-authentication-plugin/18153
|
||||||
=====================
|
|
||||||
|
|
||||||
1. Add your STEAM WEB API KEY obtainable from [steamcommunity.com/dev/apikey](http://steamcommunity.com/dev/apikey). E.g. domain name: `forum.example.org`
|
|
||||||
|
|
||||||
2. SSH into your server.
|
|
||||||
|
|
||||||
3. `cd /var/discourse`
|
|
||||||
|
|
||||||
4. Open `containers/app.yml` and make the following changes:
|
|
||||||
|
|
||||||
1. Add the API key to your Discourse Docker configuration file located at `/var/discourse/containers/app.yml`. It needs to go under `env:` in the format ` STEAM_WEB_API_KEY: SOMEKEY`
|
|
||||||
|
|
||||||
2. Add the git clone of this plugin to the plugin list under `hooks:` below the Discourse Docker Manager plugin like so: `- git clone https://github.com/defaye/discourse-steam-login.git`
|
|
||||||
|
|
||||||
3. Exit and save changes
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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].
|
|
||||||
|
|
||||||
[1]:https://github.com/defaye/discourse-steam-login
|
|
||||||
[2]:https://meta.discourse.org/t/steam-login-authentication-plugin/18153
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
.btn-social.steam {
|
||||||
|
background: #000;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
en:
|
||||||
|
js:
|
||||||
|
login:
|
||||||
|
steam:
|
||||||
|
name: "Steam"
|
||||||
|
title: "with Steam"
|
||||||
|
message: "Authenticating with Steam (make sure pop up blockers are not enabled)"
|
|
@ -0,0 +1,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: ""
|
||||||
|
|
||||||
|
errors:
|
||||||
|
steam_web_api_key_is_empty: "You must set 'steam web api key' before enabling this setting."
|
|
@ -0,0 +1,6 @@
|
||||||
|
plugins:
|
||||||
|
enable_steam_logins:
|
||||||
|
default: false
|
||||||
|
steam_web_api_key:
|
||||||
|
default: ""
|
||||||
|
secret: true
|
|
@ -0,0 +1,20 @@
|
||||||
|
class MigrateSteamAuthData < ActiveRecord::Migration[5.2]
|
||||||
|
def up
|
||||||
|
execute <<~SQL
|
||||||
|
INSERT INTO user_associated_accounts (
|
||||||
|
provider_name,
|
||||||
|
provider_uid,
|
||||||
|
user_id,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
) SELECT
|
||||||
|
'steam',
|
||||||
|
replace(key, 'steam_uid_', ''),
|
||||||
|
(value::json->>'user_id')::integer,
|
||||||
|
CURRENT_TIMESTAMP,
|
||||||
|
CURRENT_TIMESTAMP
|
||||||
|
FROM plugin_store_rows
|
||||||
|
WHERE plugin_name = 'steam'
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
end
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
*.gem
|
||||||
|
.bundle
|
||||||
|
Gemfile.lock
|
||||||
|
pkg/*
|
|
@ -0,0 +1,6 @@
|
||||||
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
# Specify your gem's dependencies in omniauth-steam.gemspec
|
||||||
|
gemspec
|
||||||
|
|
||||||
|
gem "rake"
|
|
@ -0,0 +1,70 @@
|
||||||
|
# OmniAuth Steam
|
||||||
|
|
||||||
|
This gem is an OmniAuth 1.0 strategy, supporting the Steam OpenID provider.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Add to your `Gemfile`:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
gem 'omniauth-steam'
|
||||||
|
```
|
||||||
|
|
||||||
|
And then integrate the strategy into your middleware:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
use OmniAuth::Builder do
|
||||||
|
provider :steam, "my-steam-web-api-key"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rails, you may want to add it to the middleware stack:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
||||||
|
provider :steam, ENV['STEAM_WEB_API_KEY']
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
You will need to provide your Steam Web API key to be able to retrieve information about the authenticated user. You can request one by filling out [this form](http://steamcommunity.com/dev/apikey).
|
||||||
|
|
||||||
|
For additional information, please refer to the [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
|
||||||
|
|
||||||
|
## Authentication Hash
|
||||||
|
|
||||||
|
Here's an example of the *Authentication Hash* available in `request.env['omniauth.auth']`
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
{
|
||||||
|
:provider => "steam",
|
||||||
|
:uid => "76561198010202071",
|
||||||
|
:info => {
|
||||||
|
:nickname => "Reu",
|
||||||
|
:name => "Rodrigo Navarro",
|
||||||
|
:location => "BR",
|
||||||
|
:image => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48_medium.jpg",
|
||||||
|
:urls => {
|
||||||
|
:Profile => "http://steamcommunity.com/id/rnavarro1/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
:credentials => {},
|
||||||
|
:extra => {
|
||||||
|
:raw_info => {
|
||||||
|
:steamid => "76561198010202071",
|
||||||
|
:communityvisibilitystate => 3,
|
||||||
|
:profilestate => 1,
|
||||||
|
:personaname => "Reu",
|
||||||
|
:lastlogoff => 1325637158,
|
||||||
|
:profileurl => "http://steamcommunity.com/id/rnavarro1/",
|
||||||
|
:avatar => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48.jpg",
|
||||||
|
:avatarmedium => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48_medium.jpg",
|
||||||
|
:avatarfull => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48_full.jpg",
|
||||||
|
:personastate => 1,
|
||||||
|
:realname => "Rodrigo Navarro",
|
||||||
|
:primaryclanid => "103582791432706194",
|
||||||
|
:timecreated => 1243031082,
|
||||||
|
:loccountrycode => "BR"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
|
@ -0,0 +1 @@
|
||||||
|
require "bundler/gem_tasks"
|
|
@ -0,0 +1,2 @@
|
||||||
|
require "omniauth-steam/version"
|
||||||
|
require File.expand_path("../omniauth/strategies/steam", __FILE__)
|
|
@ -0,0 +1,5 @@
|
||||||
|
module OmniAuth
|
||||||
|
module Steam
|
||||||
|
VERSION = "1.0.6"
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,8 +1,3 @@
|
||||||
# name: omniauth-steam
|
|
||||||
# about: omniauth-steam
|
|
||||||
# version: 1.0.3
|
|
||||||
# author: Rodrigo Navarro
|
|
||||||
|
|
||||||
require 'omniauth-openid'
|
require 'omniauth-openid'
|
||||||
require 'multi_json'
|
require 'multi_json'
|
||||||
|
|
||||||
|
@ -13,11 +8,12 @@ module OmniAuth
|
||||||
|
|
||||||
option :api_key, nil
|
option :api_key, nil
|
||||||
option :name, "steam"
|
option :name, "steam"
|
||||||
option :identifier, "https://steamcommunity.com/openid"
|
option :identifier, "http://steamcommunity.com/openid"
|
||||||
|
|
||||||
uid { steam_id }
|
uid { steam_id }
|
||||||
|
|
||||||
info do
|
info do
|
||||||
|
begin
|
||||||
{
|
{
|
||||||
"nickname" => player["personaname"],
|
"nickname" => player["personaname"],
|
||||||
"name" => player["realname"],
|
"name" => player["realname"],
|
||||||
|
@ -28,10 +24,19 @@ module OmniAuth
|
||||||
"FriendList" => friend_list_url
|
"FriendList" => friend_list_url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
rescue MultiJson::ParseError => exception
|
||||||
|
fail!(:steamError, exception)
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
extra do
|
extra do
|
||||||
{ "raw_info" => player }
|
begin
|
||||||
|
{ "raw_info" => player }
|
||||||
|
rescue MultiJson::ParseError => exception
|
||||||
|
fail!(:steamError, exception)
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -45,7 +50,14 @@ module OmniAuth
|
||||||
end
|
end
|
||||||
|
|
||||||
def steam_id
|
def steam_id
|
||||||
openid_response.display_identifier.split("/").last
|
@steam_id ||= begin
|
||||||
|
claimed_id = openid_response.display_identifier.split('/').last
|
||||||
|
expected_uri = %r{\Ahttps?://steamcommunity\.com/openid/id/#{claimed_id}\Z}
|
||||||
|
unless expected_uri.match(openid_response.endpoint.claimed_id)
|
||||||
|
raise 'Steam Claimed ID mismatch!'
|
||||||
|
end
|
||||||
|
claimed_id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def player_profile_uri
|
def player_profile_uri
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
require "omniauth-steam/version"
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = "omniauth-steam"
|
||||||
|
s.version = OmniAuth::Steam::VERSION
|
||||||
|
s.authors = ["Rodrigo Navarro"]
|
||||||
|
s.email = ["rnavarro1@gmail.com"]
|
||||||
|
s.homepage = "https://github.com/reu/omniauth-steam"
|
||||||
|
s.summary = "Steam strategy for OmniAuth"
|
||||||
|
|
||||||
|
s.rubyforge_project = "omniauth-steam"
|
||||||
|
|
||||||
|
s.files = `git ls-files`.split("\n") - `git ls-files examples`.split("\n")
|
||||||
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||||
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||||
|
s.require_paths = ["lib"]
|
||||||
|
|
||||||
|
s.add_runtime_dependency "omniauth-openid"
|
||||||
|
s.add_runtime_dependency "multi_json"
|
||||||
|
end
|
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
# stub: omniauth-steam 1.0.6 ruby lib
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = "omniauth-steam".freeze
|
||||||
|
s.version = "1.0.6"
|
||||||
|
|
||||||
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
||||||
|
s.require_paths = ["lib".freeze]
|
||||||
|
s.authors = ["Rodrigo Navarro".freeze]
|
||||||
|
s.date = "2018-07-30"
|
||||||
|
s.email = ["rnavarro1@gmail.com".freeze]
|
||||||
|
s.homepage = "https://github.com/reu/omniauth-steam".freeze
|
||||||
|
s.rubygems_version = "3.0.3".freeze
|
||||||
|
s.summary = "Steam strategy for OmniAuth".freeze
|
||||||
|
|
||||||
|
s.installed_by_version = "3.0.3" if s.respond_to? :installed_by_version
|
||||||
|
|
||||||
|
if s.respond_to? :specification_version then
|
||||||
|
s.specification_version = 4
|
||||||
|
|
||||||
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||||
|
s.add_runtime_dependency(%q<omniauth-openid>.freeze, [">= 0"])
|
||||||
|
s.add_runtime_dependency(%q<multi_json>.freeze, [">= 0"])
|
||||||
|
else
|
||||||
|
s.add_dependency(%q<omniauth-openid>.freeze, [">= 0"])
|
||||||
|
s.add_dependency(%q<multi_json>.freeze, [">= 0"])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
s.add_dependency(%q<omniauth-openid>.freeze, [">= 0"])
|
||||||
|
s.add_dependency(%q<multi_json>.freeze, [">= 0"])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Auth::SteamAuthenticator < ::Auth::ManagedAuthenticator
|
||||||
|
def name
|
||||||
|
'steam'
|
||||||
|
end
|
||||||
|
|
||||||
|
def enabled?
|
||||||
|
SiteSetting.enable_steam_logins
|
||||||
|
end
|
||||||
|
|
||||||
|
def register_middleware(omniauth)
|
||||||
|
omniauth.provider :steam, SiteSetting.steam_web_api_key
|
||||||
|
end
|
||||||
|
end
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
*.gem
|
||||||
|
.bundle
|
||||||
|
Gemfile.lock
|
||||||
|
pkg/*
|
|
@ -0,0 +1,6 @@
|
||||||
|
source "http://rubygems.org"
|
||||||
|
|
||||||
|
# Specify your gem's dependencies in omniauth-steam.gemspec
|
||||||
|
gemspec
|
||||||
|
|
||||||
|
gem "rake"
|
|
@ -0,0 +1,70 @@
|
||||||
|
# OmniAuth Steam
|
||||||
|
|
||||||
|
This gem is an OmniAuth 1.0 strategy, supporting the Steam OpenID provider.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Add to your `Gemfile`:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
gem 'omniauth-steam'
|
||||||
|
```
|
||||||
|
|
||||||
|
And then integrate the strategy into your middleware:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
use OmniAuth::Builder do
|
||||||
|
provider :steam, "my-steam-web-api-key"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are using Rails, you may want to add it to the middleware stack:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
||||||
|
provider :steam, ENV['STEAM_WEB_API_KEY']
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
You will need to provide your Steam Web API key to be able to retrieve information about the authenticated user. You can request one by filling out [this form](http://steamcommunity.com/dev/apikey).
|
||||||
|
|
||||||
|
For additional information, please refer to the [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
|
||||||
|
|
||||||
|
## Authentication Hash
|
||||||
|
|
||||||
|
Here's an example of the *Authentication Hash* available in `request.env['omniauth.auth']`
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
{
|
||||||
|
:provider => "steam",
|
||||||
|
:uid => "76561198010202071",
|
||||||
|
:info => {
|
||||||
|
:nickname => "Reu",
|
||||||
|
:name => "Rodrigo Navarro",
|
||||||
|
:location => "BR",
|
||||||
|
:image => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48_medium.jpg",
|
||||||
|
:urls => {
|
||||||
|
:Profile => "http://steamcommunity.com/id/rnavarro1/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
:credentials => {},
|
||||||
|
:extra => {
|
||||||
|
:raw_info => {
|
||||||
|
:steamid => "76561198010202071",
|
||||||
|
:communityvisibilitystate => 3,
|
||||||
|
:profilestate => 1,
|
||||||
|
:personaname => "Reu",
|
||||||
|
:lastlogoff => 1325637158,
|
||||||
|
:profileurl => "http://steamcommunity.com/id/rnavarro1/",
|
||||||
|
:avatar => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48.jpg",
|
||||||
|
:avatarmedium => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48_medium.jpg",
|
||||||
|
:avatarfull => "http://media.steampowered.com/steamcommunity/public/images/avatars/3c/3c91a935dca0c1e243f3a67a198b0abea9cf6d48_full.jpg",
|
||||||
|
:personastate => 1,
|
||||||
|
:realname => "Rodrigo Navarro",
|
||||||
|
:primaryclanid => "103582791432706194",
|
||||||
|
:timecreated => 1243031082,
|
||||||
|
:loccountrycode => "BR"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
|
@ -0,0 +1 @@
|
||||||
|
require "bundler/gem_tasks"
|
|
@ -0,0 +1,2 @@
|
||||||
|
require "omniauth-steam/version"
|
||||||
|
require File.expand_path("../omniauth/strategies/steam", __FILE__)
|
|
@ -0,0 +1,5 @@
|
||||||
|
module OmniAuth
|
||||||
|
module Steam
|
||||||
|
VERSION = "1.0.6"
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,72 @@
|
||||||
|
require 'omniauth-openid'
|
||||||
|
require 'multi_json'
|
||||||
|
|
||||||
|
module OmniAuth
|
||||||
|
module Strategies
|
||||||
|
class Steam < OmniAuth::Strategies::OpenID
|
||||||
|
args :api_key
|
||||||
|
|
||||||
|
option :api_key, nil
|
||||||
|
option :name, "steam"
|
||||||
|
option :identifier, "http://steamcommunity.com/openid"
|
||||||
|
|
||||||
|
uid { steam_id }
|
||||||
|
|
||||||
|
info do
|
||||||
|
begin
|
||||||
|
{
|
||||||
|
"nickname" => player["personaname"],
|
||||||
|
"name" => player["realname"],
|
||||||
|
"location" => [player["loccityid"], player["locstatecode"], player["loccountrycode"]].compact.join(", "),
|
||||||
|
"image" => player["avatarmedium"],
|
||||||
|
"urls" => {
|
||||||
|
"Profile" => player["profileurl"],
|
||||||
|
"FriendList" => friend_list_url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rescue MultiJson::ParseError => exception
|
||||||
|
fail!(:steamError, exception)
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
extra do
|
||||||
|
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)) : {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def player
|
||||||
|
@player ||= raw_info["response"]["players"].first
|
||||||
|
end
|
||||||
|
|
||||||
|
def steam_id
|
||||||
|
@steam_id ||= begin
|
||||||
|
claimed_id = openid_response.display_identifier.split('/').last
|
||||||
|
expected_uri = %r{\Ahttps?://steamcommunity\.com/openid/id/#{claimed_id}\Z}
|
||||||
|
unless expected_uri.match(openid_response.endpoint.claimed_id)
|
||||||
|
raise 'Steam Claimed ID mismatch!'
|
||||||
|
end
|
||||||
|
claimed_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def player_profile_uri
|
||||||
|
URI.parse("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=#{options.api_key}&steamids=#{steam_id}")
|
||||||
|
end
|
||||||
|
|
||||||
|
def friend_list_url
|
||||||
|
URI.parse("https://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=#{options.api_key}&steamid=#{steam_id}&relationship=friend")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
$:.push File.expand_path("../lib", __FILE__)
|
||||||
|
require "omniauth-steam/version"
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = "omniauth-steam"
|
||||||
|
s.version = OmniAuth::Steam::VERSION
|
||||||
|
s.authors = ["Rodrigo Navarro"]
|
||||||
|
s.email = ["rnavarro1@gmail.com"]
|
||||||
|
s.homepage = "https://github.com/reu/omniauth-steam"
|
||||||
|
s.summary = "Steam strategy for OmniAuth"
|
||||||
|
|
||||||
|
s.rubyforge_project = "omniauth-steam"
|
||||||
|
|
||||||
|
s.files = `git ls-files`.split("\n") - `git ls-files examples`.split("\n")
|
||||||
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||||
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
||||||
|
s.require_paths = ["lib"]
|
||||||
|
|
||||||
|
s.add_runtime_dependency "omniauth-openid"
|
||||||
|
s.add_runtime_dependency "multi_json"
|
||||||
|
end
|
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
# stub: omniauth-steam 1.0.6 ruby lib
|
||||||
|
|
||||||
|
Gem::Specification.new do |s|
|
||||||
|
s.name = "omniauth-steam".freeze
|
||||||
|
s.version = "1.0.6"
|
||||||
|
|
||||||
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
||||||
|
s.require_paths = ["lib".freeze]
|
||||||
|
s.authors = ["Rodrigo Navarro".freeze]
|
||||||
|
s.date = "2018-07-30"
|
||||||
|
s.email = ["rnavarro1@gmail.com".freeze]
|
||||||
|
s.homepage = "https://github.com/reu/omniauth-steam".freeze
|
||||||
|
s.rubygems_version = "3.0.3".freeze
|
||||||
|
s.summary = "Steam strategy for OmniAuth".freeze
|
||||||
|
|
||||||
|
s.installed_by_version = "3.0.3" if s.respond_to? :installed_by_version
|
||||||
|
|
||||||
|
if s.respond_to? :specification_version then
|
||||||
|
s.specification_version = 4
|
||||||
|
|
||||||
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||||
|
s.add_runtime_dependency(%q<omniauth-openid>.freeze, [">= 0"])
|
||||||
|
s.add_runtime_dependency(%q<multi_json>.freeze, [">= 0"])
|
||||||
|
else
|
||||||
|
s.add_dependency(%q<omniauth-openid>.freeze, [">= 0"])
|
||||||
|
s.add_dependency(%q<multi_json>.freeze, [">= 0"])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
s.add_dependency(%q<omniauth-openid>.freeze, [">= 0"])
|
||||||
|
s.add_dependency(%q<multi_json>.freeze, [">= 0"])
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,17 @@
|
||||||
|
class EnableSteamLoginsValidator
|
||||||
|
def initialize(opts = {})
|
||||||
|
@opts = opts
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_value?(val)
|
||||||
|
return true if val == 'f'
|
||||||
|
return false if SiteSetting.steam_web_api_key.blank?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def error_message
|
||||||
|
if SiteSetting.steam_web_api_key.blank?
|
||||||
|
return I18n.t('site_settings.errors.steam_web_api_key_is_empty')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
74
plugin.rb
74
plugin.rb
|
@ -1,75 +1,23 @@
|
||||||
# name: Steam authentication with Discourse
|
# name: Steam authentication with Discourse
|
||||||
# about: Authenticate with Discourse with Steam
|
# about: Authenticate with Discourse with Steam
|
||||||
# version: 1.1.1
|
# version: 2.0.0
|
||||||
# author: J. de Faye
|
# author: J. de Faye, tgxworld
|
||||||
# template author: S. Saffron
|
# template author: S. Saffron
|
||||||
|
|
||||||
|
gem 'omniauth-steam', '1.0.6'
|
||||||
|
|
||||||
if respond_to?(:register_svg_icon)
|
if respond_to?(:register_svg_icon)
|
||||||
register_svg_icon "fab fa-steam"
|
register_svg_icon "fab fa-steam"
|
||||||
end
|
end
|
||||||
|
|
||||||
require File.expand_path('../omniauth-steam.rb', __FILE__)
|
register_asset 'stylesheets/steam-login.scss'
|
||||||
|
|
||||||
class SteamAuthenticator < ::Auth::Authenticator
|
load File.expand_path("../lib/auth/steam_authenticator.rb", __FILE__)
|
||||||
|
|
||||||
def name
|
auth_provider authenticator: Auth::SteamAuthenticator.new, icon: 'steam'
|
||||||
'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"] }
|
|
||||||
|
|
||||||
retrieve_avatar(result.user, data["image"])
|
|
||||||
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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])
|
|
||||||
end
|
|
||||||
|
|
||||||
def register_middleware(omniauth)
|
|
||||||
omniauth.provider :steam, ENV['STEAM_WEB_API_KEY']
|
|
||||||
end
|
|
||||||
|
|
||||||
|
after_initialize do
|
||||||
|
[
|
||||||
|
"../lib/validators/enable_steam_logins_validator.rb"
|
||||||
|
].each { |path| load File.expand_path(path, __FILE__) }
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
CSS
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Auth::SteamAuthenticator do
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe EnableSteamLoginsValidator do
|
||||||
|
subject { described_class.new }
|
||||||
|
|
||||||
|
describe '#valid_value?' do
|
||||||
|
describe 'when steam_web_api_key has not been set' do
|
||||||
|
it "should return true when value is false" do
|
||||||
|
expect(subject.valid_value?('f')).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return false when value is true" do
|
||||||
|
expect(subject.valid_value?('t')).to eq(false)
|
||||||
|
|
||||||
|
expect(subject.error_message).to eq(I18n.t(
|
||||||
|
'site_settings.errors.steam_web_api_key_is_empty'
|
||||||
|
))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when steam_web_api_key has been set' do
|
||||||
|
before do
|
||||||
|
SiteSetting.steam_web_api_key = "somekey"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true when value is false" do
|
||||||
|
expect(subject.valid_value?('f')).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return true when value is true' do
|
||||||
|
expect(subject.valid_value?('t')).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue