omniauth-tenzing 0.0.1

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: 7eb3761e945ad60924e83ddc606115df689a32f0
4
+ data.tar.gz: 03116d056eeaa5e378781cc133a718efd9c17c30
5
+ SHA512:
6
+ metadata.gz: 3ba4671ce077ae1e59bb11a890befbbe8aefbb8b6245eb51edb766ee3fd28a15ad0bb4e417d6d10372a1e30c12e06aa91c4490669868f3b152a03116cf9cccb1
7
+ data.tar.gz: 20f0488d28d776772a0a956929d6b20095a0b33d864a12b75ef9ef80c342c612e6f2e79add13ad4201d2a546269434709dd6f86c7c3541c2a7948a53ea0ac6bc
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create 1.9.3@omniauth-linkedin
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth-tenzing.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'growl'
11
+ gem 'rb-fsevent'
12
+ gem 'multi_json'
13
+ end
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+
8
+ guard 'bundler' do
9
+ watch('Gemfile')
10
+ watch(/^.+\.gemspec/)
11
+ end
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # OmniAuth tenzing
2
+
3
+ This gem contains the tenzing strategy for OmniAuth 1.0 .
4
+
5
+ tenzing uses the OAuth 1.0a flow, you can read about it here: https://developer.tenzing.com/documents/authentication
6
+
7
+ ## How To Use It
8
+
9
+ Usage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile` along side omniauth:
10
+
11
+ ```ruby
12
+ gem 'omniauth'
13
+ gem 'omniauth-tenzing'
14
+ ```
15
+
16
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
17
+
18
+ ```ruby
19
+ Rails.application.config.middleware.use OmniAuth::Builder do
20
+ provider :tenzing, "consumer_key", "consumer_secret"
21
+ end
22
+ ```
23
+
24
+ You will obviously have to put in your key and secret, which you get when you register your app with tenzing (they call them API Key and Secret Key).
25
+
26
+ Now just follow the README at: https://github.com/intridea/omniauth
27
+
28
+ ## Additional permissions
29
+
30
+ tenzing recently (August 2012) provided the ability to request different permissions by specifying a scope. You can find more information on the different permissions at https://developer.tenzing.com/documents/authentication
31
+
32
+ By default, omniauth-tenzing requests the following permissions:
33
+
34
+ ```ruby
35
+ "r_basicprofile r_emailaddress"
36
+ ```
37
+
38
+ This allows us to obtain enough information from tenzing to satisfy the requirements for the basic auth hash schema.
39
+
40
+ To change the scope, simply change your initializer to something like this:
41
+
42
+ ```ruby
43
+ Rails.application.config.middleware.use OmniAuth::Builder do
44
+ provider :tenzing, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network'
45
+ end
46
+ ```
47
+
48
+ One thing to note is the fact that when you ask for extra permissions, you will probably want to specify the array of fields that you want returned in the omniauth hash. If you don't then only the default fields (see below) will be returned which would defeat the purpose of asking for the extra permissions. So do the following:
49
+
50
+ ```ruby
51
+ Rails.application.config.middleware.use OmniAuth::Builder do
52
+ provider :tenzing, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "connections"]
53
+ end
54
+ ```
55
+
56
+ We have to repeat the list of default fields in order to get the extra 'connections' field.
57
+
58
+ The list of default fields is as follows:
59
+
60
+ ```ruby
61
+ ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location"]
62
+ ```
63
+
64
+ To see a complete list of available fields, consult the tenzing documentation at https://developer.tenzing.com/documents/profile-fields
65
+
66
+ ## Using It With The tenzing Gem
67
+
68
+ You may find that you want to use OmniAuth for authentication, but you want to use an API wrapper such as this one https://github.com/pengwynn/tenzing to actually make your api calls. But the tenzing gem provides it's own way to authenticate with tenzing via OAuth. In this case you can do the following.
69
+
70
+ Configure the tenzing gem with your consumer key and secret:
71
+
72
+ ```ruby
73
+ tenzing.configure do |config|
74
+ config.token = "consumer_key"
75
+ config.secret = "consumer_secret"
76
+ end
77
+ ```
78
+
79
+ Use OmniAuth as per normal to obtain an access token and an access token secret for your user. Now create the tenzing client and authorize it using the access token and secret that you ontained via OmniAuth:
80
+
81
+ ```ruby
82
+ client = tenzing::Client.new
83
+ client.authorize_from_access("access_token", "access_token_secret")
84
+ ```
85
+
86
+ You can now make API calls as per normal e.g.:
87
+
88
+ ```ruby
89
+ client.profile
90
+ client.add_share({:comment => "blah"})
91
+ ```
92
+
93
+ ## Note on Patches/Pull Requests
94
+
95
+ - Fork the project.
96
+ - Make your feature addition or bug fix.
97
+ - Add tests for it. This is important so I don’t break it in a future version unintentionally.
98
+ - Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
99
+ - Send me a pull request. Bonus points for topic branches.
100
+
101
+ ## License
102
+
103
+ Copyright (c) 2011 by Alan Skorkin
104
+
105
+ 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:
106
+
107
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
108
+
109
+ 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.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'multi_json'
5
+ gem 'omniauth-tenzing', :path => '../'
data/example/config.ru ADDED
@@ -0,0 +1,33 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-tenzing'
4
+
5
+ ENV['TENZING_CONSUMER_KEY'] = "----"
6
+ ENV['TENZING_CONSUMER_SECRET'] = "----"
7
+
8
+ class App < Sinatra::Base
9
+ get '/' do
10
+ redirect '/auth/tenzing'
11
+ end
12
+
13
+ get '/auth/:provider/callback' do
14
+ content_type 'application/json'
15
+ MultiJson.encode(request.env)
16
+ end
17
+
18
+ get '/auth/failure' do
19
+ content_type 'application/json'
20
+ MultiJson.encode(request.env)
21
+ end
22
+ end
23
+
24
+ use Rack::Session::Cookie, :secret => "change_me"
25
+
26
+ use OmniAuth::Builder do
27
+ #note that the scope is different from the default
28
+ #we also have to repeat the default fields in order to get
29
+ #the extra 'connections' field in there
30
+ provider :linkedin, ENV['TENZING_CONSUMER_KEY'], ENV['TENZING_CONSUMER_SECRET'], :scope => 'r_fullprofile+r_emailaddress+r_network', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "connections"]
31
+ end
32
+
33
+ run App.new
@@ -0,0 +1,9 @@
1
+ require "omniauth-tenzing/version"
2
+ require 'omniauth/strategies/tenzing'
3
+
4
+
5
+ module Omniauth
6
+ module Tenzing
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Tenzing
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'omniauth/strategies/oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Tenzing < OmniAuth::Strategies::OAuth
6
+ option :name, "tenzing"
7
+
8
+ option :client_options, {
9
+ :site => 'http://id.tenzing.urbegi.com',
10
+ :access_token_path => '/oauth/access_token',
11
+ :authorize_path => '/oauth/authorize'
12
+ }
13
+
14
+ uid { raw_info['id'] }
15
+
16
+ info do
17
+ {
18
+ :email => raw_info['email'],
19
+ :name => raw_info['name'],
20
+ :last_name => raw_info['last_name'],
21
+ }
22
+ end
23
+
24
+ extra do
25
+ { 'raw_info' => raw_info }
26
+ end
27
+
28
+ def raw_info
29
+ @raw_info ||= MultiJson.decode(access_token.get("/api/v1/user_info").body)
30
+ end
31
+
32
+ def request_phase
33
+ options.request_params ||= {}
34
+ options.request_params[:scope] = options.scope.gsub("+", " ")
35
+ super
36
+ end
37
+
38
+ def nil_if_empty(value)
39
+ (value.nil? || value.empty?) ? nil : value
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ OmniAuth.config.add_camelization 'tenzing', 'Tenzing'
46
+
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-tenzing/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-tenzing"
7
+ s.version = Omniauth::Tenzing::VERSION
8
+ s.authors = ["Alan Skorkin", "Endika Gutiérrez"]
9
+ s.email = ["alan@skorks.com", "me@endika.net"]
10
+ s.homepage = "https://github.com/endSly/omniauth-tenzing"
11
+ s.summary = %q{Tenzing strategy for OmniAuth.}
12
+ s.description = %q{Tenzing strategy for OmniAuth.}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency 'omniauth-oauth', '~> 1.0'
20
+
21
+ s.add_development_dependency 'rspec', '~> 2.7'
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'webmock'
24
+ s.add_development_dependency 'rack-test'
25
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe "OmniAuth::Strategies::tenzing" do
4
+ subject do
5
+ OmniAuth::Strategies::Tenzing.new(nil, @options || {})
6
+ end
7
+
8
+ it 'should add a camelization for itself' do
9
+ OmniAuth::Utils.camelize('tenzing').should == 'tenzing'
10
+ end
11
+
12
+ context 'client options' do
13
+ it 'has correct tenzing site' do
14
+ subject.options.client_options.site.should eq('https://api.tenzing.com')
15
+ end
16
+
17
+ it 'has correct request token path' do
18
+ subject.options.client_options.request_token_path.should eq('/uas/oauth/requestToken')
19
+ end
20
+
21
+ it 'has correct access token path' do
22
+ subject.options.client_options.access_token_path.should eq('/uas/oauth/accessToken')
23
+ end
24
+
25
+ it 'has correct authorize url' do
26
+ subject.options.client_options.authorize_url.should eq('https://www.tenzing.com/uas/oauth/authenticate')
27
+ end
28
+ end
29
+
30
+ context '#uid' do
31
+ before :each do
32
+ subject.stub(:raw_info) { { 'id' => '123' } }
33
+ end
34
+
35
+ it 'returns the id from raw_info' do
36
+ subject.uid.should eq('123')
37
+ end
38
+ end
39
+
40
+ context 'returns info hash conformant with omniauth auth hash schema' do
41
+ before :each do
42
+ subject.stub(:raw_info) { {} }
43
+ end
44
+
45
+ context 'and therefore has all the necessary fields' do
46
+ it {subject.info.should have_key :name}
47
+ it {subject.info.should have_key :name}
48
+ it {subject.info.should have_key :email}
49
+ it {subject.info.should have_key :nickname}
50
+ it {subject.info.should have_key :first_name}
51
+ it {subject.info.should have_key :last_name}
52
+ it {subject.info.should have_key :location}
53
+ it {subject.info.should have_key :description}
54
+ it {subject.info.should have_key :image}
55
+ it {subject.info.should have_key :phone}
56
+ it {subject.info.should have_key :urls}
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'rspec'
5
+ require 'rack/test'
6
+ require 'webmock/rspec'
7
+ require 'omniauth'
8
+ require 'omniauth-tenzing'
9
+
10
+ RSpec.configure do |config|
11
+ config.include WebMock::API
12
+ config.include Rack::Test::Methods
13
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
14
+ end
data/todo.txt ADDED
@@ -0,0 +1 @@
1
+ - need some more tests to make sure location can be parsed correctly
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tenzing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alan Skorkin
8
+ - Endika Gutiérrez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '2.7'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '2.7'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: webmock
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rack-test
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: Tenzing strategy for OmniAuth.
85
+ email:
86
+ - alan@skorks.com
87
+ - me@endika.net
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .rvmrc
95
+ - Gemfile
96
+ - Guardfile
97
+ - README.md
98
+ - Rakefile
99
+ - example/Gemfile
100
+ - example/config.ru
101
+ - lib/omniauth-tenzing.rb
102
+ - lib/omniauth-tenzing/version.rb
103
+ - lib/omniauth/strategies/tenzing.rb
104
+ - omniauth-tenzing.gemspec
105
+ - spec/omniauth/strategies/linkedin_spec.rb
106
+ - spec/spec_helper.rb
107
+ - todo.txt
108
+ homepage: https://github.com/endSly/omniauth-tenzing
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.0.0
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Tenzing strategy for OmniAuth.
131
+ test_files:
132
+ - spec/omniauth/strategies/linkedin_spec.rb
133
+ - spec/spec_helper.rb