omniauth-cmply 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .rvmrc
2
+ .rbenv-version
3
+ .bundle
4
+ .idea
5
+ .idea/*.*
6
+ .DS_Store
7
+ coverage/*.*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rake'
4
+ # Specify your gem's dependencies in omniauth-twitter.gemspec
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-cmply (0.0.7)
5
+ multi_json (~> 1.3)
6
+ omniauth-oauth2 (~> 1.1.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.3.2)
12
+ crack (0.3.1)
13
+ diff-lcs (1.1.3)
14
+ faraday (0.8.4)
15
+ multipart-post (~> 1.1)
16
+ hashie (1.2.0)
17
+ httpauth (0.1)
18
+ jwt (0.1.5)
19
+ multi_json (>= 1.0)
20
+ multi_json (1.3.6)
21
+ multipart-post (1.1.5)
22
+ oauth2 (0.8.0)
23
+ faraday (~> 0.8)
24
+ httpauth (~> 0.1)
25
+ jwt (~> 0.1.4)
26
+ multi_json (~> 1.0)
27
+ rack (~> 1.2)
28
+ omniauth (1.1.0)
29
+ hashie (~> 1.2)
30
+ rack
31
+ omniauth-oauth2 (1.1.0)
32
+ oauth2 (~> 0.8.0)
33
+ omniauth (~> 1.0)
34
+ rack (1.4.1)
35
+ rack-test (0.6.1)
36
+ rack (>= 1.0)
37
+ rake (0.9.2.2)
38
+ rspec (2.11.0)
39
+ rspec-core (~> 2.11.0)
40
+ rspec-expectations (~> 2.11.0)
41
+ rspec-mocks (~> 2.11.0)
42
+ rspec-core (2.11.1)
43
+ rspec-expectations (2.11.2)
44
+ diff-lcs (~> 1.1.3)
45
+ rspec-mocks (2.11.2)
46
+ simplecov (0.6.4)
47
+ multi_json (~> 1.0)
48
+ simplecov-html (~> 0.5.3)
49
+ simplecov-html (0.5.3)
50
+ webmock (1.8.9)
51
+ addressable (>= 2.2.7)
52
+ crack (>= 0.1.7)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ omniauth-cmply!
59
+ rack-test
60
+ rake
61
+ rspec (~> 2.7)
62
+ simplecov
63
+ webmock
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # OmniAuth CMP.LY
2
+
3
+ This gem contains the CMP.LY strategy for OmniAuth. CMP.LY uses the OAuth 2.0 flow.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-cmply'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+ Or install it yourself as:
19
+
20
+ ```sh
21
+ $ gem install omniauth-cmply
22
+ ```
23
+
24
+
25
+
26
+
27
+ ## Usage
28
+
29
+ ### Rails
30
+
31
+ If you're using Rails, you need to add the strategy to your `Gemfile`:
32
+
33
+ ```ruby
34
+ gem 'omniauth-cmply'
35
+ ```
36
+
37
+ or you can pull them in directly from Github e.g.:
38
+
39
+ ```ruby
40
+ gem 'omniauth-cmply', :git => 'https://github.com/cmply/omniauth-cmply.git'
41
+ ```
42
+
43
+ Once you've added the gem to your project, you need to add the following to your `config/initializers/omniauth.rb`:
44
+
45
+ ```ruby
46
+ Rails.application.config.middleware.use OmniAuth::Builder do
47
+ provider :cmply, "consumer_key", "consumer_secret"
48
+ end
49
+ ```
50
+
51
+ Enter your `consumer_key` and `consumer_secret`, which you receive when you register your application with CMP.LY (they
52
+ call them API Key and Secret Key).
53
+
54
+ Now just follow the README at: https://github.com/intridea/omniauth
55
+
56
+ ### Sinatra
57
+
58
+ ```ruby
59
+ require 'omniauth'
60
+ require 'omniauth-cmply'
61
+
62
+ use Rack::Session::Cookie
63
+ use OmniAuth::Builder do
64
+ provider :cmply, "consumer_key", "consumer_secret"
65
+ end
66
+
67
+ get '/auth/:provider/callback' do
68
+ # Do something with auth_hash
69
+ redirect to('/')
70
+ end
71
+
72
+ def auth_hash
73
+ request.env['omniauth.auth']
74
+ end
75
+ ```
76
+
77
+ ## Supported Rubies
78
+
79
+ OmniAuth CMP.LY is tested under 1.8.7, 1.9.2, 1.9.3 and Ruby Enterprise Edition.
80
+
81
+ ## Note on Patches/Pull Requests
82
+
83
+ - Fork the project.
84
+ - Make your feature addition or bug fix.
85
+ - Add tests for it. This is important so I don’t break it in a future version unintentionally.
86
+ - Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump
87
+ version in a commit by itself I can ignore when I pull)
88
+ - Send me a pull request. Bonus points for topic branches.
89
+
90
+ ## License
91
+
92
+ Copyright (c) 2012 by CMP.LY
93
+
94
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
95
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
96
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
97
+ persons to whom the Software is furnished to do so, subject to the following conditions:
98
+
99
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of
100
+ the Software.
101
+
102
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
103
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
104
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
105
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,48 @@
1
+ require 'omniauth-oauth2'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Cmply < OmniAuth::Strategies::OAuth2
7
+ option :name, 'cmply'
8
+ option :client_options, {:authorize_path => '/oauth/authorize',:site => 'https://api.cmp.ly'}
9
+
10
+ #uid { access_token.params[:user_id] }
11
+ uid { raw_info['_id'] }
12
+
13
+ info do
14
+ {
15
+ :nickname => raw_info['user_name'],
16
+ :name => raw_info['full_name'],
17
+ :first_name => raw_info['first_name'],
18
+ :last_name => raw_info['last_name'],
19
+ :image => raw_info['profile_image_url'],
20
+ :description => raw_info['bio'],
21
+ :email => raw_info['email']
22
+ }
23
+ end
24
+
25
+ extra do
26
+ { :raw_info => raw_info }
27
+ end
28
+
29
+ def raw_info
30
+ @raw_info ||= MultiJson.load(access_token.get('/v2/users/verify-credentials.json').body)
31
+ rescue ::Errno::ETIMEDOUT
32
+ raise ::Timeout::Error
33
+ end
34
+
35
+ alias :old_request_phase :request_phase
36
+
37
+ def request_phase
38
+ screen_name = session['omniauth.params'] ? session['omniauth.params']['screen_name'] : nil
39
+ if screen_name && !screen_name.empty?
40
+ options[:authorize_params] ||= {}
41
+ options[:authorize_params].merge!(:force_login => 'true', :screen_name => screen_name)
42
+ end
43
+ old_request_phase
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Cmply
3
+ VERSION = "0.0.9"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-cmply/version"
2
+ require 'omniauth/strategies/cmply'
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-cmply/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-cmply"
7
+ s.version = OmniAuth::Cmply::VERSION
8
+ s.authors = ["Michael De Lorenzo"]
9
+ s.email = ["api@cmp.ly"]
10
+ s.homepage = "https://github.com/cmply/omniauth-cmply"
11
+ s.summary = %q{OmniAuth strategy for CMP.LY}
12
+ s.description = %q{OmniAuth strategy for CMP.LY}
13
+
14
+ s.rubyforge_project = "omniauth-twitter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'multi_json', '~> 1.3'
22
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1.0'
23
+ s.add_development_dependency 'rspec', '~> 2.7'
24
+ s.add_development_dependency 'rack-test'
25
+ s.add_development_dependency 'simplecov'
26
+ s.add_development_dependency 'webmock'
27
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Cmply do
4
+ subject do
5
+ OmniAuth::Strategies::Cmply.new({})
6
+ end
7
+
8
+ context "client options" do
9
+ it 'should have correct name' do
10
+ subject.options.name.should eq("cmply")
11
+ end
12
+
13
+ it 'should have correct site' do
14
+ subject.options.client_options.site.should eq('http://api.cmp.ly')
15
+ end
16
+
17
+ it 'should have correct authorize url' do
18
+ subject.options.client_options.authorize_path.should eq('/oauth/authorize')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-cmply'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-cmply
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.9
6
+ platform: ruby
7
+ authors:
8
+ - Michael De Lorenzo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-08-22 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: multi_json
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "1.3"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: omniauth-oauth2
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 1.1.0
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "2.7"
46
+ type: :development
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rack-test
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: simplecov
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id006
81
+ description: OmniAuth strategy for CMP.LY
82
+ email:
83
+ - api@cmp.ly
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README.md
95
+ - Rakefile
96
+ - lib/omniauth-cmply.rb
97
+ - lib/omniauth-cmply/version.rb
98
+ - lib/omniauth/strategies/cmply.rb
99
+ - omniauth-cmply.gemspec
100
+ - spec/omniauth/strategies/cmply_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: https://github.com/cmply/omniauth-cmply
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options: []
107
+
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: "0"
122
+ requirements: []
123
+
124
+ rubyforge_project: omniauth-twitter
125
+ rubygems_version: 1.8.23
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: OmniAuth strategy for CMP.LY
129
+ test_files:
130
+ - spec/omniauth/strategies/cmply_spec.rb
131
+ - spec/spec_helper.rb