omniauth-bookingsync 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d4ee1cab6909a9ebc58c93121e5c27ab5f84f3d5
4
+ data.tar.gz: c6a108cd9601234fdb3f69427859124a2c6d2dea
5
+ SHA512:
6
+ metadata.gz: fa8a7a5a141e61bfd77f5727b4bf0d983dfda407a20d3f01b63540ebf3a91134fbc0ed49c5216992c730a33cc49d3bf30f60dc811b5767147bfbed369446627d
7
+ data.tar.gz: d0b8298e4ce9282c13de9df53f30b597d2f44ae5a178c8f6ade0e76fb74a798de9ee88461e09117db2924ec72b863ee8bbf1c7a7f1f421e1bfc956a3a02c633e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.rbc
2
+ *.sw?
3
+ *.gem
4
+ .DS_Store
5
+ .bundle
6
+ .rbx
7
+ .rvmrc
8
+ .yardoc
9
+ Gemfile.lock
10
+ bin
11
+ coverage*
12
+ doc
13
+ gemfiles
14
+ pkg
15
+ rdoc
16
+ rerun.txt
17
+ tags
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format=nested
2
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - ruby-head
8
+ - ree
9
+ - jruby-18mode # JRuby in 1.8 mode
10
+ - jruby-19mode # JRuby in 1.9 mode
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :example do
6
+ gem 'sinatra'
7
+ end
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # OmniAuth BookingSync
2
+
3
+ This is an OmniAuth 1.1 strategy for authenticating to BookingSync. To
4
+ use it, you'll need to sign up for an OAuth2 Application ID and Secret
5
+ on the [BookingSync Application's Registration Page](https://www.bookingsync.com/en/partners).
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-bookingsync'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ `OmniAuth::Strategies::BookingSync` is simply a Rack middleware. Read the OmniAuth 1.1 docs for detailed instructions: https://github.com/intridea/omniauth.
20
+
21
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
22
+
23
+ ```ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :bookingsync, ENV['BOOKINGSYNC_APPLICATION_ID'], ENV['BOOKINGSYNC_SECRET']
26
+ end
27
+ ```
28
+
29
+ ## Supported Rubies
30
+
31
+ OmniAuth BookingSync is tested under 1.8.7, 1.9.2, 1.9.3, 2.0.0, Ruby-head, Ruby Enterprise Edition, JRuby (1.8 and 1.9 mode).
32
+
33
+ [![CI Build
34
+ Status](https://secure.travis-ci.org/BookingSync/omniauth-bookingsync.png)](http://travis-ci.org/BookingSync/omniauth-bookingsync)
35
+
36
+ ## License
37
+
38
+ Copyright (c) 2014 Sébastien Grosjean and [BookingSync.com](http://www.bookingsync.com)
39
+
40
+ 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:
41
+
42
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
43
+
44
+ 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,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler'
3
+ Bundler.setup :default, :development, :example
4
+ require 'sinatra'
5
+ require 'omniauth-bookingsync'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'bundler'
9
+ Bundler.setup :default, :development, :example
10
+ require 'sinatra'
11
+ require 'omniauth-bookingsync'
12
+ end
13
+
14
+ use Rack::Session::Cookie
15
+
16
+ use OmniAuth::Builder do
17
+ provider :bookingsync, APPLICATION_ID, SECRET
18
+ end
19
+
20
+ get '/' do
21
+ <<-HTML
22
+ <ul>
23
+ <li><a href='/auth/bookingsync'>Sign in with BookingSync</a></li>
24
+ </ul>
25
+ HTML
26
+ end
27
+
28
+ get '/auth/:provider/callback' do
29
+ content_type 'text/plain'
30
+ request.env['omniauth.auth'].to_hash.inspect
31
+ end
32
+
33
+ get '/auth/failure' do
34
+ content_type 'text/plain'
35
+ params[:message]
36
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth/bookingsync/version'
2
+ require 'omniauth/strategies/bookingsync'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module BookingSync
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class BookingSync < OmniAuth::Strategies::OAuth2
6
+ option :name, 'bookingsync'
7
+
8
+ option :client_options, {
9
+ :site => 'https://www.bookingsync.com/'
10
+ }
11
+
12
+ uid { raw_info["id"] }
13
+
14
+ info do
15
+ {
16
+ :business_name => raw_info['business_name']
17
+ }
18
+ end
19
+
20
+ def raw_info
21
+ @raw_info ||= access_token.get('/api/v3/accounts').parsed['accounts'].first
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ OAuth2::Response::CONTENT_TYPES['application/vnd.api+json'] ||= :json
28
+
29
+ OmniAuth.config.add_camelization 'bookingsync', 'BookingSync'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/omniauth/bookingsync/version", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "omniauth-bookingsync"
6
+ gem.version = OmniAuth::BookingSync::VERSION
7
+ gem.platform = Gem::Platform::RUBY
8
+ gem.authors = ["Sebastien Grosjean"]
9
+ gem.email = ["dev@bookingsync.com"]
10
+ gem.homepage = "https://github.com/BookingSync/omniauth-bookingsync"
11
+ gem.summary = %q{An OmniAuth 1.0 strategy for BookingSync OAuth2 identification.}
12
+ gem.description = %q{An OmniAuth 1.0 strategy for BookingSync OAuth2 identification.}
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'omniauth', '~> 1.1'
20
+ gem.add_dependency 'omniauth-oauth2', '~> 1.1'
21
+
22
+ gem.add_development_dependency 'rspec', '~> 2.7'
23
+ gem.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-bookingsync'
3
+
4
+ describe OmniAuth::Strategies::BookingSync do
5
+ before do
6
+ OmniAuth.config.test_mode = true
7
+ end
8
+
9
+ subject do
10
+ OmniAuth::Strategies::BookingSync.new(nil, @options || {})
11
+ end
12
+
13
+ it_should_behave_like 'an oauth2 strategy'
14
+
15
+ describe '#client' do
16
+ it 'should have the correct site' do
17
+ subject.client.site.should eq("https://www.bookingsync.com/")
18
+ end
19
+
20
+ it 'should have the correct authorization url' do
21
+ subject.client.options[:authorize_url].should eq("/oauth/authorize")
22
+ end
23
+
24
+ it 'should have the correct token url' do
25
+ subject.client.options[:token_url].should eq('/oauth/token')
26
+ end
27
+ end
28
+
29
+ describe '#callback_path' do
30
+ it 'should have the correct callback path' do
31
+ subject.callback_path.should eq('/auth/bookingsync/callback')
32
+ end
33
+ end
34
+
35
+ describe '#raw_info' do
36
+ it 'should fetch account info from api v3' do
37
+ subject.stub(:access_token => double)
38
+ response = double(:parsed => {'accounts' => [{'id' => 1}]})
39
+ subject.access_token.should_receive(:get).with('/api/v3/accounts').
40
+ and_return(response)
41
+ subject.raw_info.should eq({'id' => 1})
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,36 @@
1
+ shared_examples 'an oauth2 strategy' do
2
+ describe '#client' do
3
+ it 'should be initialized with symbolized client_options' do
4
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
5
+ subject.client.options[:authorize_url].should == 'https://example.com'
6
+ end
7
+ end
8
+
9
+ describe '#authorize_params' do
10
+ it 'should include any authorize params passed in the :authorize_params option' do
11
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
12
+ subject.authorize_params['foo'].should eq('bar')
13
+ subject.authorize_params['baz'].should eq('zip')
14
+ end
15
+
16
+ it 'should include top-level options that are marked as :authorize_options' do
17
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
18
+ subject.authorize_params['scope'].should eq('bar')
19
+ subject.authorize_params['foo'].should eq('baz')
20
+ end
21
+ end
22
+
23
+ describe '#token_params' do
24
+ it 'should include any token params passed in the :token_params option' do
25
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
26
+ subject.token_params['foo'].should eq('bar')
27
+ subject.token_params['baz'].should eq('zip')
28
+ end
29
+
30
+ it 'should include top-level options that are marked as :token_options' do
31
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
32
+ subject.token_params['scope'].should eq('bar')
33
+ subject.token_params['foo'].should eq('baz')
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-bookingsync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastien Grosjean
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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
+ description: An OmniAuth 1.0 strategy for BookingSync OAuth2 identification.
70
+ email:
71
+ - dev@bookingsync.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - Gemfile
80
+ - README.md
81
+ - Rakefile
82
+ - example/sinatra.rb
83
+ - lib/omniauth-bookingsync.rb
84
+ - lib/omniauth/bookingsync/version.rb
85
+ - lib/omniauth/strategies/bookingsync.rb
86
+ - omniauth-bookingsync.gemspec
87
+ - spec/omniauth/strategies/bookingsync_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/support/shared_examples.rb
90
+ homepage: https://github.com/BookingSync/omniauth-bookingsync
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.0.14
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: An OmniAuth 1.0 strategy for BookingSync OAuth2 identification.
113
+ test_files:
114
+ - spec/omniauth/strategies/bookingsync_spec.rb
115
+ - spec/spec_helper.rb
116
+ - spec/support/shared_examples.rb