├── .gitignore ├── Gemfile ├── config ├── settings.yml └── locales │ └── server.en.yml ├── assets └── stylesheets │ └── disqus.scss └── plugin.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'omniauth' 4 | gem 'omniauth-oauth2' 5 | -------------------------------------------------------------------------------- /config/settings.yml: -------------------------------------------------------------------------------- 1 | plugins: 2 | disqus_login_enabled: 3 | default: false 4 | client: true 5 | disqus_client_id: 6 | default: '' 7 | disqus_client_secret: 8 | default: '' 9 | -------------------------------------------------------------------------------- /config/locales/server.en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | site_settings: 3 | disqus_client_id: 'Disqus Client ID' 4 | disqus_client_secret: 'Disqus Client Secret' 5 | disqus_login_enabled: 'Enable Disqus Social Login' -------------------------------------------------------------------------------- /assets/stylesheets/disqus.scss: -------------------------------------------------------------------------------- 1 | .btn-social.disqus { 2 | background-color: #2e9fff; 3 | 4 | &:before { 5 | background-image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMjAwIDIwMCIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMjAwIDIwMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxwYXRoIGZpbGw9IiNGRkZGRkYiIGNsYXNzPSJzdDAiIGQ9Ik0xMDMuNiwxOTcuMWMtMjMuOCwwLTQ1LjUtOC43LTYyLjMtMjMuMUwwLDE3OS43bDE2LTM5LjRjLTUuNy0xMi43LTguNy0yNi40LTguNy00MC4zYzAtNTMuNiw0My4xLTk3LjEsOTYuNC05Ny4xYzUzLjIsMCw5Ni40LDQzLjUsOTYuNCw5Ny4xQzIwMCwxNTMuNiwxNTYuOSwxOTcuMSwxMDMuNiwxOTcuMXogTTE1Ni4zLDk5Ljd2LTAuM2MwLTI4LTE5LjgtNDgtNTMuOC00OEg2NS42djk3LjFoMzYuM0MxMzYuMiwxNDguNiwxNTYuMywxMjcuNywxNTYuMyw5OS43eiBNMTAyLjgsMTI0LjdIOTIuMVY3NS4zaDEwLjhjMTUuOCwwLDI2LjMsOSwyNi4zLDI0LjZ2MC4zQzEyOS4xLDExNS44LDExOC42LDEyNC43LDEwMi44LDEyNC43eiIvPjwvc3ZnPg0K"); 6 | background-size: 16px; 7 | display: inline-block; 8 | width: 16px; 9 | height: 16px; 10 | content: ""; 11 | } 12 | 13 | svg { 14 | display: none; 15 | } 16 | } 17 | 18 | .mobile-view { 19 | .btn-social.disqus { 20 | background-position-x: 18px; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /plugin.rb: -------------------------------------------------------------------------------- 1 | # name: discourse-disqus 2 | # about: Log in to Discourse with your Disqus account 3 | # version: 1.0 4 | # author: Aaron Parecki 5 | # url: https://github.com/aaronpk/discourse-disqus-oauth 6 | 7 | require 'auth/oauth2_authenticator' 8 | 9 | enabled_site_setting :disqus_login_enabled 10 | 11 | PLUGIN_NAME = 'discourse-disqus'.freeze 12 | 13 | register_asset 'stylesheets/disqus.scss' 14 | 15 | after_initialize do 16 | 17 | module ::Disqus 18 | PLUGIN_NAME = 'discourse-disqus'.freeze 19 | 20 | class Engine < ::Rails::Engine 21 | engine_name PLUGIN_NAME 22 | isolate_namespace Disqus 23 | end 24 | 25 | def self.store 26 | @store ||= PluginStore.new(PLUGIN_NAME) 27 | end 28 | 29 | def self.get(key) 30 | store.get(key) 31 | end 32 | 33 | def self.set(key, value) 34 | store.set(key, value) 35 | end 36 | 37 | end 38 | 39 | class ::OmniAuth::Strategies::Disqus 40 | option :name, 'disqus' 41 | option :scope, 'read,email' 42 | 43 | option :client_options, { 44 | :site => 'https://disqus.com', 45 | :authorize_url => '/api/oauth/2.0/authorize/', 46 | :token_url => '/api/oauth/2.0/access_token/' 47 | } 48 | 49 | option :authorize_params, response_type: 'code' 50 | 51 | uid { 52 | access_token.params['user_id'] 53 | } 54 | 55 | info do 56 | { 57 | :name => raw_info['username'], 58 | :nickname => raw_info['username'], 59 | :email => raw_info['email'], 60 | :location => raw_info['location'], 61 | :description => raw_info['about'], 62 | :image => raw_info['avatar']['small']['permalink'], 63 | :urls => { 64 | 'profileUrl' => raw_info['profileUrl'] 65 | } 66 | } 67 | end 68 | 69 | extra do 70 | { 71 | :raw_info => raw_info 72 | } 73 | end 74 | 75 | def callback_url 76 | full_host + script_name + callback_path 77 | end 78 | 79 | def raw_info 80 | url = '/api/3.0/users/details.json' 81 | params = { 82 | 'api_key' => access_token.client.id, 83 | 'access_token' => access_token.token 84 | } 85 | 86 | @raw_info ||= access_token.get(url, :params => params).parsed['response'] 87 | end 88 | end 89 | 90 | end 91 | 92 | class OmniAuth::Strategies::Disqus < OmniAuth::Strategies::OAuth2 93 | end 94 | 95 | class Auth::DisqusAuthenticator < Auth::OAuth2Authenticator 96 | def register_middleware(omniauth) 97 | omniauth.provider :disqus, 98 | setup: lambda { |env| 99 | strategy = env['omniauth.strategy'] 100 | strategy.options[:client_id] = SiteSetting.disqus_client_id 101 | strategy.options[:client_secret] = SiteSetting.disqus_client_secret 102 | strategy.options[:redirect_uri] = "#{Discourse.base_url}/auth/disqus/callback" 103 | } 104 | end 105 | 106 | def enabled? 107 | SiteSetting.disqus_login_enabled 108 | end 109 | end 110 | 111 | auth_provider pretty_name: 'Disqus', 112 | title: 'with Disqus', 113 | message: 'Authentication with Disqus (make sure pop up blockers are not enabled)', 114 | frame_width: 840, 115 | frame_height: 570, 116 | authenticator: Auth::DisqusAuthenticator.new('disqus', trusted: true), 117 | enabled_setting: 'disqus_login_enabled' 118 | 119 | --------------------------------------------------------------------------------