omniauth-cube7 0.0.2

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4653bf8d31c2a6281edc4326971d2b17a3f2951e
4
+ data.tar.gz: 5ec1f60364142d9079b4e923453eb9c5ea87444b
5
+ SHA512:
6
+ metadata.gz: 46a3719b5f4699451b586ca0fd0928ccb2a267ac866efb39971bbfed7677f6dfad54457c5d93d2d1dd78b544c63e5bb4b0ce423683b87caf31608dc8ffe2a574
7
+ data.tar.gz: fe9d2d8e1889cedee6e2b0840a17e8ad20cdd2057e274c3ad55370d4c76f4ffc78c45eb03af3dd3a01eba3236652a9955c461fbc30c0d773f5e78feef00c2eae
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ before_install:
2
+ - gem update bundler
3
+ - bundle --version
4
+ - gem update --system 2.1.11
5
+ - gem --version
6
+ language: ruby
7
+ rvm:
8
+ - 1.8.7
9
+ - 1.9.2
10
+ - 1.9.3
11
+ - 2.0.0
12
+ - 2.1.0
13
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-cube7.gemspec
4
+ gem 'minitest-rg', :require => "minitest/rg"
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ruo
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,89 @@
1
+ [![Build Status](https://travis-ci.org/siera26/omniauth-cube7.png?branch=master)](https://travis-ci.org/siera26/omniauth-cube7)
2
+
3
+ # Omniauth CUBE7
4
+
5
+ [CUBE7](http://cube7.com) is an international Sales-Platform with all the functions and aspects of a social network
6
+
7
+ This gem contains the CUBE7 strategy for OmniAuth.
8
+
9
+ CUBE7 uses OAuth 2. This strategy implements the browser variant of the "Sign in with CUBE7" flow.
10
+
11
+ ## Before You Begin
12
+
13
+ You should have already installed OmniAuth into your app; if not, read the [OmniAuth README](https://github.com/intridea/omniauth) to get started.
14
+
15
+ Now contact administrator of CUBE7 to create an application. Then you should get application_id and secret_key from him.
16
+ Make sure to send a callback URL to administrator or else you may get authentication errors. (It doesn't matter what it is, just that it is set.)
17
+
18
+ ## Usage
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'omniauth-cube7'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install omniauth-cube7
33
+
34
+ Next, tell OmniAuth about this provider. For a Rails app, your `config/initializers/omniauth.rb` file should look like this:
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :cube7, "APPLICATION_ID", "SECRET_KEY"
39
+ end
40
+ ```
41
+
42
+ Replace APPLICATION_ID and SECRET_KEY with the appropriate values you obtained from administrator earlier.
43
+
44
+ ## Authentication Hash
45
+
46
+ An example auth hash available in `request.env['omniauth.auth']`:
47
+
48
+ ```ruby
49
+ {
50
+ "provider"=>:cube7,
51
+ "uid"=>11,
52
+ "info"=>
53
+ {
54
+ "email"=>"ab@sevendevs.de",
55
+ "first_name"=>"Alexander",
56
+ "last_name"=>"Bierbrauer",
57
+ "baio_status"=>1
58
+ },
59
+ "credentials"=>
60
+ {
61
+ "token"=>"e8d6f6685e08ca8e3874a36d421de0020d6f714a3576c2c543726b18d5c3ce89",
62
+ "expires_at"=>1391245607,
63
+ "expires"=>true
64
+ },
65
+ "extra"=>{
66
+ "raw_info"=>
67
+ {
68
+ "id"=>11,
69
+ "email"=>"ab@sevendevs.de",
70
+ "gender"=>"Male",
71
+ "first_name"=>"Alexander",
72
+ "second_name"=>"Bierbrauer",
73
+ "baio_status"=>1
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ ## Supported Rubies
80
+
81
+ OmniAuth CUBE7 is tested under 1.8.7, 1.9.2, 1.9.3, 2.0.0, and Ruby Enterprise Edition.
82
+
83
+ ## Contributing
84
+
85
+ 1. Fork it
86
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
87
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
88
+ 4. Push to the branch (`git push origin my-new-feature`)
89
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ task :console do
6
+ puts "Loading development console..."
7
+ system("irb -r omniauth-cube7")
8
+ end
9
+
10
+ task :help do
11
+ puts "Available rake tasks: "
12
+ puts "rake console - Run a IRB console with all enviroment loaded"
13
+ puts "rake test - Run tests"
14
+ end
15
+
16
+ task :test do
17
+ Dir.chdir('tests')
18
+ end
19
+
20
+ Rake::TestTask.new(:test) do |t|
21
+ t.libs << '../lib'
22
+ t.libs << '../tests'
23
+ t.test_files = FileList['*_test.rb']
24
+ t.verbose = false
25
+ end
26
+
27
+ task :default => :test
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Cube7
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth/cube7/version"
2
+ require "omniauth/strategies/cube7"
@@ -0,0 +1,34 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Cube7 < OmniAuth::Strategies::OAuth2
6
+ # change the class name and the :name option to match your application name
7
+ option :name, :cube7
8
+
9
+ option :client_options, {
10
+ :site => "http://www.cube7.com",
11
+ :authorize_url => "/oauth/authorize"
12
+ }
13
+
14
+ uid { raw_info["id"] }
15
+
16
+ info do
17
+ {
18
+ :email => raw_info["email"],
19
+ :first_name => raw_info["first_name"],
20
+ :last_name => raw_info["second_name"],
21
+ :baio_status => raw_info["baio_status"],
22
+ }
23
+ end
24
+
25
+ extra do
26
+ { :raw_info => raw_info }
27
+ end
28
+
29
+ def raw_info
30
+ @raw_info ||= access_token.get('/api/me.json').parsed
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ require "omniauth/cube7"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/cube7/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-cube7"
8
+ spec.version = Omniauth::Cube7::VERSION
9
+ spec.authors = ["Ruo"]
10
+ spec.email = ["siera04@gmail.com"]
11
+ spec.description = "Cube7 strategy for Omniauth"
12
+ spec.summary = "Cube7 strategy for Omniauth"
13
+ spec.homepage = "https://github.com/siera26/omniauth-cube7"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.1.1'
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+
25
+ spec.add_development_dependency 'minitest'
26
+ spec.add_development_dependency 'mocha'
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require 'omniauth-cube7'
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ class StrategyTest < StrategyTestCase
7
+ include OAuth2StrategyTests
8
+ end
9
+
10
+ class ClientTest < StrategyTestCase
11
+ test 'has correct Cube7 site' do
12
+ assert_equal 'http://www.cube7.com', strategy.client.site
13
+ end
14
+
15
+ test 'has correct authorize url' do
16
+ assert_equal '/oauth/authorize', strategy.client.options[:authorize_url]
17
+ end
18
+
19
+ test 'has correct token url' do
20
+ assert_equal '/oauth/token', strategy.client.options[:token_url]
21
+ end
22
+ end
@@ -0,0 +1,86 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ module OAuth2StrategyTests
3
+ def self.included(base)
4
+ base.class_eval do
5
+ include ClientTests
6
+ include AuthorizeParamsTests
7
+ include CSRFAuthorizeParamsTests
8
+ include TokenParamsTests
9
+ end
10
+ end
11
+
12
+ module ClientTests
13
+ extend BlockTestHelper
14
+
15
+ test 'should be initialized with symbolized client_options' do
16
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
17
+ assert_equal 'https://example.com', strategy.client.options[:authorize_url]
18
+ end
19
+ end
20
+
21
+ module AuthorizeParamsTests
22
+ extend BlockTestHelper
23
+
24
+ test 'should include any authorize params passed in the :authorize_params option' do
25
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
26
+ assert_equal 'bar', strategy.authorize_params['foo']
27
+ assert_equal 'zip', strategy.authorize_params['baz']
28
+ end
29
+
30
+ test 'should include top-level options that are marked as :authorize_options' do
31
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
32
+ assert_equal 'bar', strategy.authorize_params['scope']
33
+ assert_equal 'baz', strategy.authorize_params['foo']
34
+ end
35
+
36
+ test 'should exclude top-level options that are not passed' do
37
+ @options = { :authorize_options => [:bar] }
38
+ refute_has_key :bar, strategy.authorize_params
39
+ refute_has_key 'bar', strategy.authorize_params
40
+ end
41
+ end
42
+
43
+ module CSRFAuthorizeParamsTests
44
+ extend BlockTestHelper
45
+
46
+ test 'should store random state in the session when none is present in authorize or request params' do
47
+ assert_includes strategy.authorize_params.keys, 'state'
48
+ refute_empty strategy.authorize_params['state']
49
+ refute_empty strategy.session['omniauth.state']
50
+ assert_equal strategy.authorize_params['state'], strategy.session['omniauth.state']
51
+ end
52
+
53
+ # test 'should store state in the session when present in authorize params vs. a random one' do
54
+ # @request.stubs(:params).returns({ 'state' => 'bar' })
55
+ # @options = { :authorize_params => { :state => 'bar' } }
56
+ # refute_empty strategy.authorize_params['state']
57
+ # assert_equal 'bar', strategy.authorize_params[:state]
58
+ # refute_empty strategy.session['omniauth.state']
59
+ # assert_equal 'bar', strategy.session['omniauth.state']
60
+ # end
61
+
62
+ # test 'should store state in the session when present in request params vs. a random one' do
63
+ # @request.stubs(:params).returns({ 'state' => 'foo' })
64
+ # refute_empty strategy.authorize_params['state']
65
+ # assert_equal 'foo', strategy.authorize_params[:state]
66
+ # refute_empty strategy.session['omniauth.state']
67
+ # assert_equal 'foo', strategy.session['omniauth.state']
68
+ # end
69
+ end
70
+
71
+ module TokenParamsTests
72
+ extend BlockTestHelper
73
+
74
+ test 'should include any authorize params passed in the :token_params option' do
75
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
76
+ assert_equal 'bar', strategy.token_params['foo']
77
+ assert_equal 'zip', strategy.token_params['baz']
78
+ end
79
+
80
+ test 'should include top-level options that are marked as :token_options' do
81
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
82
+ assert_equal 'bar', strategy.token_params['scope']
83
+ assert_equal 'baz', strategy.token_params['foo']
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,57 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/autorun'
3
+ require 'minitest/unit'
4
+ require 'minitest/rg'
5
+ require 'mocha/setup'
6
+ require 'omniauth/strategies/cube7'
7
+
8
+ OmniAuth.config.test_mode = true
9
+
10
+ module BlockTestHelper
11
+ def test(name, &blk)
12
+ method_name = "test_#{name.gsub(/\s+/, '_')}"
13
+ raise "Method already defined: #{method_name}" if instance_methods.include?(method_name.to_sym)
14
+ define_method method_name, &blk
15
+ end
16
+ end
17
+
18
+ module CustomAssertions
19
+ def assert_has_key(key, hash, msg = nil)
20
+ msg = message(msg) { "Expected #{hash.inspect} to have key #{key.inspect}" }
21
+ assert hash.has_key?(key), msg
22
+ end
23
+
24
+ def refute_has_key(key, hash, msg = nil)
25
+ msg = message(msg) { "Expected #{hash.inspect} not to have key #{key.inspect}" }
26
+ refute hash.has_key?(key), msg
27
+ end
28
+ end
29
+
30
+ class TestCase < Minitest::Unit::TestCase
31
+ extend BlockTestHelper
32
+ include CustomAssertions
33
+ end
34
+
35
+ class StrategyTestCase < TestCase
36
+ def setup
37
+ @request = stub('Request')
38
+ @request.stubs(:params).returns({})
39
+ @request.stubs(:cookies).returns({})
40
+ @request.stubs(:env).returns({})
41
+ @request.stubs(:ssl?).returns(false)
42
+
43
+ @client_id = '123'
44
+ @client_secret = '53cr3tz'
45
+ end
46
+
47
+ def strategy
48
+ @strategy ||= begin
49
+ args = [@client_id, @client_secret, @options].compact
50
+ OmniAuth::Strategies::Cube7.new(nil, *args).tap do |strategy|
51
+ strategy.stubs(:request).returns(@request)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ Dir[File.expand_path('../support/**/*', __FILE__)].each &method(:require)
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-cube7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Ruo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Cube7 strategy for Omniauth
84
+ email:
85
+ - siera04@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/omniauth-cube7.rb
97
+ - lib/omniauth/cube7.rb
98
+ - lib/omniauth/cube7/version.rb
99
+ - lib/omniauth/strategies/cube7.rb
100
+ - omniauth-cube7.gemspec
101
+ - tests/cube7_test.rb
102
+ - tests/support/shared_examples.rb
103
+ - tests/test_helper.rb
104
+ homepage: https://github.com/siera26/omniauth-cube7
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.6
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Cube7 strategy for Omniauth
128
+ test_files: []