From 37c8c97f9bfc6b7652361fcf5bc105f109eea70f Mon Sep 17 00:00:00 2001 From: de Faye Date: Sun, 20 Jul 2014 20:01:34 +0100 Subject: [PATCH] Initial commit --- LICENSE | 21 ++++++++++++++++++ README.md | 18 ++++++++++++++++ plugin.rb | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 plugin.rb diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..173b623 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 J. de Faye + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..10fded4 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +Discourse Steam Login +===================== + +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/docker` + +4. Open `containers/app.yml` and make the following changes: + + 1. Add the API key to your Discourse Docker configuration file located at `/var/docker/containers/app.yml`. It needs to go under `env:` in the format ` STEAM_WEB_API_KEY: 'KEY'` + + 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. \ No newline at end of file diff --git a/plugin.rb b/plugin.rb new file mode 100644 index 0000000..6bff73a --- /dev/null +++ b/plugin.rb @@ -0,0 +1,64 @@ +# name: Steam authentication with Discourse +# about: Authenticate with Discourse with Steam +# version: 0.2.0 +# author: J. de Faye, Sam Saffron + +gem 'omniauth-steam', '1.0.3', git: 'https://github.com/reu/omniauth-steam.git' + +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"] + name = data["name"] + 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.name = name + result.extra_data = { steam_uid: steam_uid } + + 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 <