viki_disqus 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGZlMjc2ODM1NDg1ZWRkNjM0NDJhOGI5YTYwMDMxNTgwZDFiMmIzZA==
5
+ data.tar.gz: !binary |-
6
+ MzFhZDE3ZmVjNWRjNmRhOThiZmI3NmI3NmM5ODI3Y2JiZjVhZGQ1MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzQ4YjFkOTQ3OWYwMTkwZDY5MDEyZDI4YzdiNDIyMTdhN2Q0YzRiNGQ4ZDhk
10
+ ZjNmYWU1MWUxZmU3MWZkMTg3NTJmNTBjMThkN2U0MGRhMWVjNzUyYTllNGNk
11
+ YzVmMzZkMDNlMzBkMjU0ODQ5ZjVlN2E1ZTM1MWNmM2NlMWRjYjQ=
12
+ data.tar.gz: !binary |-
13
+ MzI1YTc4ZjU2ZTEzNTZmMmY0NzU1MWUyMWFkZTM4OTA1ZWJjMThiYjcyMTA5
14
+ ZTlhOGU5ZmM0ODU5N2E2NGE1ODVkNDkyNDBiNmE1NDEyZmQ0MzhkNjFhYWZl
15
+ MWY0Y2YyNDU1OWFmOGM0MTZmZWYwNTFkZDBjZjFjZDQyZmE3MjU=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swo
4
+ *.swp
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in viki_disqus_gem.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pang Yan Han
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Viki Disqus Gem
2
+
3
+ This is a gem used by the Viki web application for integrating Disqus
4
+ Single Sign-On (SSO). Users who log in to Viki can post comments on Disqus
5
+ using the same Viki account, without the need for another login.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'viki_disqus'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install viki_disqus
20
+
21
+ ## Usage
22
+
23
+ **NOTE:** You will have to read
24
+ http://help.disqus.com/customer/portal/articles/236206-integrating-single-sign-on
25
+ for setup instructions on the Disqus end.
26
+
27
+ You need to set these 2 environment variables to appropriate values:
28
+
29
+ * `DISQUS_SECRET_KEY`
30
+ * `DISQUS_PUBLIC_KEY`
31
+
32
+ They will be used by the VikiDisqus::SSO class.
33
+ Their values can be accessed through:
34
+
35
+ * `VikiDisqus::SSO::DISQUS_SECRET_KEY`
36
+ * `VikiDisqus::SSO::DISQUS_PUBLIC_KEY`
37
+
38
+ These functions are available publicly:
39
+
40
+ * `VikiDisqus::SSO::remote_auth_s3(optionsHash, timestampNow)`
41
+ * `VikiDisqus::SSO::signature(optionsHash, timestampNow)`
42
+ * `VikiDisqus::SSO::message(optionsHash)`
43
+
44
+ You should make use of the `VikiDisqus::SSO::remote_auth_s3` function
45
+ (which uses `VikiDisqus::SSO::signature` and
46
+ `VikiDisqus::SSO::message` internally).
47
+
48
+ You will need to embed this snippet of JavaScript, according to instructions
49
+ from Disqus. The template looks like:
50
+
51
+ ```javascript
52
+ var disqus_config = function () {
53
+ // The generated payload which authenticates users with Disqus
54
+ this.page.remote_auth_s3 = '<message> <hmac> <timestamp>';
55
+ this.page.api_key = 'public_api_key';
56
+ }
57
+ ```
58
+
59
+ On the Viki web application, it looks like:
60
+
61
+ ```javascript
62
+ var disqus_config = function () {
63
+ this.page.remote_auth_s3 = '<%= VikiDisqus::SSO.remote_auth_s3(opts, Time.now.to_i) %>';
64
+ this.page.api_key = '<%= VikiDisqus::SSO::DISQUS_PUBLIC_KEY %>';
65
+ }
66
+ ```
67
+
68
+ ## Running Tests
69
+
70
+ `bundle exec rspec spec`
71
+
72
+ or
73
+
74
+ `rspec spec`
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,29 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+
4
+ module VikiDisqus
5
+ # Disqus SSO Doc: http://help.disqus.com/customer/portal/articles/236206-integrating-single-sign-on
6
+ class SSO
7
+ DISQUS_SECRET_KEY = ENV["DISQUS_SECRET_KEY"]
8
+ DISQUS_PUBLIC_KEY = ENV["DISQUS_PUBLIC_KEY"]
9
+
10
+ def self.remote_auth_s3(opts, timestamp)
11
+ "#{message(opts)} #{signature(opts, timestamp)} #{timestamp}"
12
+ end
13
+
14
+ def self.signature(opts, timestamp)
15
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'),
16
+ DISQUS_SECRET_KEY,
17
+ "#{message(opts)} #{timestamp}")
18
+ end
19
+
20
+ # Validate message: http://disqus.com/api/sso/
21
+ def self.message(opts)
22
+ message = {'id' => opts['id'], 'username' => opts['username'], 'email' => opts['email']}
23
+ message.merge!({'url' => opts['url']}) if opts.has_key?('url')
24
+ message.merge!({'avatar'=> opts['avatar']}) if opts.has_key?('avatar')
25
+
26
+ Base64.strict_encode64(message.to_json).gsub("\n", "")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module VikiDisqus
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "viki_disqus/version"
2
+
3
+ module VikiDisqus
4
+ # Your code goes here...
5
+ end
6
+
7
+ require "viki_disqus/SSO"
@@ -0,0 +1,4 @@
1
+ require "viki_disqus"
2
+
3
+ RSpec.configure do |config|
4
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "../spec_helper"
2
+ require "json"
3
+
4
+ describe VikiDisqus::SSO do
5
+ let(:user_hash) { {'id' => 1, "username" => "admin", "email" => "admin@viki.com"} }
6
+ let(:timestamp) { 1360142584 }
7
+
8
+ describe "#signature" do
9
+ it "generate the signature of a given user" do
10
+ described_class.signature(user_hash, timestamp).should ==
11
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'),
12
+ VikiDisqus::SSO::DISQUS_SECRET_KEY,
13
+ "#{Base64.strict_encode64(user_hash.to_json).gsub("\n", "")} #{timestamp}")
14
+ end
15
+ end
16
+
17
+ describe "#message" do
18
+ it "return the base64 message" do
19
+ described_class.message(user_hash).should ==
20
+ Base64.encode64(user_hash.to_json).gsub("\n", "")
21
+ end
22
+
23
+ it "handles optional acceptable hash" do
24
+ user_hash.merge!({'url'=>"some_url", 'avatar'=>"some_avatar"})
25
+ described_class.message(user_hash).should ==
26
+ Base64.encode64(user_hash.to_json).gsub("\n", "")
27
+ end
28
+
29
+ it "does not handle unacceptable hash" do
30
+ extra_user_hash = user_hash.merge({'some_extra'=>'hash_not_needed_by_disqus'})
31
+ described_class.message(extra_user_hash).should ==
32
+ Base64.encode64(user_hash.to_json).gsub("\n", "")
33
+ end
34
+ end
35
+
36
+ describe "#remote_auth_s3" do
37
+ it "returns the signed message" do
38
+ described_class.remote_auth_s3(user_hash, timestamp).should ==
39
+ "#{described_class.message(user_hash)} #{described_class.signature(user_hash, timestamp)} #{timestamp}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'viki_disqus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "viki_disqus"
8
+ spec.version = VikiDisqus::VERSION
9
+ spec.authors = ["Tang Chin Yong", "Pang Yan Han"]
10
+ spec.email = ["engineering@viki.com"]
11
+ spec.description = %q{Viki Disqus Gem - for Single Sign-On (SSO)}
12
+ spec.summary = %q{Viki Disqus Gem - for Single Sign-On (SSO)}
13
+ spec.homepage = "http://engineering.viki.com"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", "~> 2.13"
23
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: viki_disqus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tang Chin Yong
8
+ - Pang Yan Han
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '2.13'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '2.13'
56
+ description: Viki Disqus Gem - for Single Sign-On (SSO)
57
+ email:
58
+ - engineering@viki.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/viki_disqus.rb
69
+ - lib/viki_disqus/SSO.rb
70
+ - lib/viki_disqus/version.rb
71
+ - spec/spec_helper.rb
72
+ - spec/viki_disqus/SSO_spec.rb
73
+ - viki_disqus.gemspec
74
+ homepage: http://engineering.viki.com
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.1.11
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Viki Disqus Gem - for Single Sign-On (SSO)
97
+ test_files:
98
+ - spec/spec_helper.rb
99
+ - spec/viki_disqus/SSO_spec.rb