omniauth-freshbooks 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d88fb041e0997960f30403719705bac233608111
4
+ data.tar.gz: 197055ac42993750af5af03a6b2493b894522001
5
+ SHA512:
6
+ metadata.gz: aa9c1eed70c222856b6b7be5512d99c285e98463ce35f4bb2e8179b34be9aaeadeb65b912c0316fff631b0f2bb9fd79f87d6f07991fe083a437045adb07628f5
7
+ data.tar.gz: c89b081c04b7cd4ead79e973f4817f9ce23aad08568b67f8cb5f61407185d37bf344f2c254c02e96d0b37ccd9f56f3d98120924b2018facbce7d440efee97dd1
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Francois Deschenes
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.
@@ -0,0 +1,27 @@
1
+ # OmniAuth FreshBooks
2
+
3
+ This is the OmniAuth strategy for authentication to [FreshBooks](http://www.freshbooks.com).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-freshbooks'
11
+ ```
12
+
13
+ And then, you need to add the following to your `config/initializers/omniauth.rb`:
14
+
15
+ ```ruby
16
+ Rails.application.config.middleware.use OmniAuth::Builder do
17
+ provider :freshbooks, "consumer_key", "consumer_secret"
18
+ end
19
+ ```
20
+
21
+ You will obviously have to put in your key and secret, which you get when you [register as a consumer with FreshBooks](http://developers.freshbooks.com/authentication-2/#OAuth).
22
+
23
+ ## Options
24
+
25
+ The options are:
26
+
27
+ * **site** The FreshBooks root URI for this site. This can also be passed as a query string parameter although if one specified in your initializer, it will always take precedence. *Example:* `https://sample.freshbooks.com`
@@ -0,0 +1,6 @@
1
+ require "omniauth/freshbooks/version"
2
+ require "omniauth/strategies/freshbooks"
3
+
4
+ module Omniauth
5
+ module Freshbooks; end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Freshbooks
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,71 @@
1
+ require "multi_xml"
2
+ require "omniauth-oauth"
3
+ require "oauth/signature/plaintext"
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class FreshBooks < OmniAuth::Strategies::OAuth
8
+ option :client_options, {
9
+ access_token_path: "/oauth/oauth_access.php",
10
+ authorize_path: "/oauth/oauth_authorize.php",
11
+ request_token_path: "/oauth/oauth_request.php",
12
+ signature_method: "PLAINTEXT"
13
+ }
14
+
15
+ uid { options.client_options.site + "/" + raw_info["staff_id"] }
16
+
17
+ info do
18
+ {
19
+ name: [raw_info["first_name"], raw_info["last_name"]].compact.join(" "),
20
+ first_name: raw_info["first_name"],
21
+ last_name: raw_info["last_name"],
22
+ email: raw_info["email"],
23
+ nickname: raw_info["username"],
24
+ location: [raw_info["city"], raw_info["state"], raw_info["country"]].compact.join(", "),
25
+ phone: raw_info["business_phone"],
26
+ urls: {
27
+ "FreshBooks" => options.client_options.site
28
+ }
29
+ }
30
+ end
31
+
32
+ extra do
33
+ { raw_info: raw_info }
34
+ end
35
+
36
+ def redirect(*args)
37
+ session["oauth"][name.to_s].merge!({
38
+ "site" => options.client_options.site
39
+ })
40
+ super
41
+ end
42
+
43
+ def request_phase
44
+ options.client_options.site = options.site.presence || session["omniauth.params"]["site"].presence
45
+
46
+ unless options.client_options.site
47
+ OmniAuth::Form.build(title: (options.title.presence || "FreshBooks Authentication")) do |form|
48
+ form.text_field "URL", "site"
49
+ end.to_response
50
+ else
51
+ super
52
+ end
53
+ rescue URI::InvalidURIError
54
+ return fail!(:invalid_site)
55
+ rescue Net::HTTPRetriableError
56
+ return fail!(:invalid_site)
57
+ end
58
+
59
+ def callback_phase
60
+ options.client_options.site = session["oauth"][name.to_s]["site"] if session["oauth"].present?
61
+ super
62
+ end
63
+
64
+ def raw_info
65
+ @raw_info ||= MultiXml.parse(access_token.post("/api/2.1/xml-in", '<?xml version="1.0" encoding="utf-8"?><request method="staff.current"></request>').body).fetch("response").fetch("staff")
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ OmniAuth.config.add_camelization "freshbooks", "FreshBooks"
@@ -0,0 +1,82 @@
1
+ require "spec_helper"
2
+ require "omniauth/freshbooks"
3
+
4
+ describe OmniAuth::Strategies::FreshBooks do
5
+ subject do
6
+ OmniAuth::Strategies::FreshBooks.new(nil, @options || {})
7
+ end
8
+
9
+ describe "#client" do
10
+ it "has correct access token path" do
11
+ subject.options.client_options["access_token_path"].should eq("/oauth/oauth_access.php")
12
+ end
13
+
14
+ it "has correct authorize path" do
15
+ subject.options.client_options["authorize_path"].should eq("/oauth/oauth_authorize.php")
16
+ end
17
+
18
+ it "has correct request token path" do
19
+ subject.options.client_options["request_token_path"].should eq("/oauth/oauth_request.php")
20
+ end
21
+
22
+ it "has correct signature method" do
23
+ subject.options.client_options["signature_method"].should eq("PLAINTEXT")
24
+ end
25
+ end
26
+
27
+ describe "#info" do
28
+ before :each do
29
+ @raw_info = {
30
+ "staff_id" => "1",
31
+ "username" => "jsmith",
32
+ "first_name" => "John",
33
+ "last_name" => "Smith",
34
+ "email" => "jsmith@example.org",
35
+ "business_phone" => "(123) 456-7890",
36
+ "mobile_phone" => "",
37
+ "rate" => "0",
38
+ "last_login" => "2008-11-20 13:26:00",
39
+ "number_of_logins" => "13",
40
+ "signup_date" => "2008-10-22 13:57:00",
41
+ "street1" => "123 ABC Street",
42
+ "street2" => "",
43
+ "city" => "Toronto",
44
+ "state" => "Ontario",
45
+ "country" => "Canada",
46
+ "code" => "M1M 1A1"
47
+ }
48
+
49
+ subject.stub(:raw_info) { @raw_info }
50
+ end
51
+
52
+ context "when data is present in raw info" do
53
+ it "returns the combined name" do
54
+ subject.info[:name].should eq("John Smith")
55
+ end
56
+
57
+ it "returns the first name" do
58
+ subject.info[:first_name].should eq("John")
59
+ end
60
+
61
+ it "returns the last name" do
62
+ subject.info[:last_name].should eq("Smith")
63
+ end
64
+
65
+ it "returns the email" do
66
+ subject.info[:email].should eq("jsmith@example.org")
67
+ end
68
+
69
+ it "returns the nickname" do
70
+ subject.info[:nickname].should eq("jsmith")
71
+ end
72
+
73
+ it "returns the user location" do
74
+ subject.info[:location].should eq("Toronto, Ontario, Canada")
75
+ end
76
+
77
+ it "returns the phone" do
78
+ subject.info[:phone].should eq("(123) 456-7890")
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+ $:.unshift File.expand_path("../../lib", __FILE__)
3
+
4
+ require "bundler/setup"
5
+ require "rspec"
6
+
7
+ RSpec.configure do |config|
8
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-freshbooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Francois Deschenes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: multi_json
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: omniauth-oauth
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: multi_xml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: FreshBooks OAuth strategy for OmniAuth
98
+ email:
99
+ - fdeschenes@me.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/omniauth/freshbooks/version.rb
107
+ - lib/omniauth/freshbooks.rb
108
+ - lib/omniauth/strategies/freshbooks.rb
109
+ - spec/omniauth/strategies/freshbooks_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/fdeschenes/omniauth-freshbooks
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: FreshBooks OAuth strategy for OmniAuth
135
+ test_files:
136
+ - spec/omniauth/strategies/freshbooks_spec.rb
137
+ - spec/spec_helper.rb