two-legged-oauth 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.
- data/.gitignore +8 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +19 -0
- data/README.md +74 -0
- data/Rakefile +1 -0
- data/lib/two-legged-oauth.rb +6 -0
- data/lib/two-legged-oauth/access_token.rb +70 -0
- data/lib/two-legged-oauth/version.rb +3 -0
- data/test/access_token_test.rb +47 -0
- data/test/settings.yml.example +5 -0
- data/two-legged-oauth.gemspec +24 -0
- metadata +111 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Fraudpointer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Two Legged OAuth
|
2
|
+
|
3
|
+
* https://github.com/fraudpointer/two-legged-oauth-ruby
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
The purpose of this gem is to make the [oauth gem](https://github.com/oauth/oauth-ruby) play nice
|
8
|
+
with Google's custom 2 legged OAuth (2LO), used specifically for [Google Apps APIs](http://code.google.com/googleapps/) accessed from [Google Apps Marketplace applications](http://code.google.com/googleapps/marketplace/).
|
9
|
+
|
10
|
+
For more info on the 2 legged OAuth see these :
|
11
|
+
|
12
|
+
* [Google Apps OAuth](http://code.google.com/apis/accounts/docs/OAuth.html#GoogleAppsOAuth)
|
13
|
+
* [2 Legged OAuth in PHP](http://gdatatips.blogspot.com/2008/11/2-legged-oauth-in-php.html)
|
14
|
+
* [Google Apps Marketplace Authentication Best Practices](http://code.google.com/googleapps/marketplace/best_practices.html)
|
15
|
+
* [Google Data APIs 2 Legged OAuth](http://code.google.com/apis/gdata/docs/auth/oauth.html#2LeggedOAuth)
|
16
|
+
|
17
|
+
This gem has been tested with the following libraries so far and seems to be working ok :
|
18
|
+
|
19
|
+
* [GoogleContactsApi](https://github.com/aliang/google_contacts_api)
|
20
|
+
* [GoogleSpreadsheet](https://github.com/gimite/google-spreadsheet-ruby) (with some [custom fixes](https://github.com/fraudpointer/google-spreadsheet-ruby/tree/two_legged_oauth) that hopefully will get integrated to the official gem)
|
21
|
+
* [Google Apps Marketplace Ruby tutorial](http://code.google.com/googleapps/marketplace/tutorial_ruby.html)
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
### Bundler
|
26
|
+
|
27
|
+
Add on your Gemfile :
|
28
|
+
|
29
|
+
gem 'two-legged-oauth'
|
30
|
+
|
31
|
+
### By hand
|
32
|
+
|
33
|
+
On the console :
|
34
|
+
|
35
|
+
gem install two-legged-oauth
|
36
|
+
|
37
|
+
On your code :
|
38
|
+
|
39
|
+
require 'two-legged-oauth'
|
40
|
+
|
41
|
+
## Usage
|
42
|
+
|
43
|
+
Create a normal consumer instance :
|
44
|
+
|
45
|
+
consumer = OAuth::Consumer.new("key", "secret")
|
46
|
+
|
47
|
+
Initialize a TwoLeggedAccessToken specifying the xoauth_requestor_id :
|
48
|
+
|
49
|
+
access_token = OAuth::TwoLeggedAccessToken.new(oauth_consumer, "user@domain.com")
|
50
|
+
|
51
|
+
Pass that access token to Google Data libraries (or your custom scripts) :
|
52
|
+
|
53
|
+
g = GoogleSpreadsheet.login_with_oauth(access_token)
|
54
|
+
|
55
|
+
## Internals
|
56
|
+
|
57
|
+
This thing works by rewriting the requested URL on-the-fly and appends the xoauth_requestor_id param appropriately. This may be dangerous at times so be aware that some well hidden bugs may come up...
|
58
|
+
|
59
|
+
## Bugs/fixes
|
60
|
+
|
61
|
+
...
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Tested contributions are always welcome! Here's what you should do:
|
66
|
+
|
67
|
+
1. Clone the repo
|
68
|
+
2. Run the tests
|
69
|
+
3. Write some test-driven code
|
70
|
+
4. Create a pull request
|
71
|
+
|
72
|
+
# License
|
73
|
+
|
74
|
+
two-legged-oauth is copyright 2011 by [Fraudpointer](http://www.fraudpointer.com), released under the MIT License (see LICENSE for details).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module OAuth
|
2
|
+
|
3
|
+
# The TwoLeggedAccessToken is used for the actual "real" web service calls that you perform
|
4
|
+
# against Google Apps APIs with 2LO (2 legged authentication).
|
5
|
+
# Use this instead of the normal {AccessToken} and it should play out of the box.
|
6
|
+
class TwoLeggedAccessToken < AccessToken
|
7
|
+
|
8
|
+
attr_accessor :xoauth_requestor_id
|
9
|
+
|
10
|
+
# @param consumer [OAuth::Consumer] a properly initialized oauth consumer
|
11
|
+
# @param xoauth_requestor_id [String] usually the email of the user (user@google-apps-domain.com)
|
12
|
+
def initialize(consumer, xoauth_requestor_id)
|
13
|
+
super(consumer)
|
14
|
+
@xoauth_requestor_id = xoauth_requestor_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(http_method, path, *arguments)
|
18
|
+
Logger.debug("Original OAuth request path : #{path}")
|
19
|
+
request_uri = URI.parse(path)
|
20
|
+
|
21
|
+
if xoauth_requestor_id
|
22
|
+
xoauth_param = "xoauth_requestor_id=#{xoauth_requestor_id}"
|
23
|
+
escaped_xoauth_param = "xoauth_requestor_id=#{CGI.escape(xoauth_requestor_id)}"
|
24
|
+
|
25
|
+
if request_uri.query.present?
|
26
|
+
request_uri.query.gsub!(xoauth_param, '')
|
27
|
+
request_uri.query.gsub!(escaped_xoauth_param, '')
|
28
|
+
end
|
29
|
+
|
30
|
+
request_uri.query = request_uri.query.present? ?
|
31
|
+
"#{request_uri.query}&#{escaped_xoauth_param}" :
|
32
|
+
"#{escaped_xoauth_param}"
|
33
|
+
|
34
|
+
path = request_uri.to_s
|
35
|
+
end
|
36
|
+
|
37
|
+
Logger.debug("Hacked OAuth request path : #{path}")
|
38
|
+
super(http_method, path, *arguments)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
# Logger helper
|
44
|
+
class Logger
|
45
|
+
|
46
|
+
@@logger = nil
|
47
|
+
|
48
|
+
class StdLogger
|
49
|
+
def debug(message)
|
50
|
+
puts message
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.debug(message)
|
55
|
+
logger.debug(message)
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def self.logger
|
61
|
+
@@logger ||= if defined? Rails
|
62
|
+
@@logger = Rails.logger
|
63
|
+
else
|
64
|
+
@@logger = StdLogger.new
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'two-legged-oauth'
|
4
|
+
|
5
|
+
class AccessTokenTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_initialize
|
14
|
+
@access_token = OAuth::TwoLeggedAccessToken.new(consumer, xoauth_requestor_id)
|
15
|
+
|
16
|
+
assert_equal xoauth_requestor_id, @access_token.xoauth_requestor_id
|
17
|
+
assert_equal consumer, @access_token.consumer
|
18
|
+
assert_equal Hash.new, @access_token.params
|
19
|
+
assert_equal "", @access_token.token
|
20
|
+
assert_equal "", @access_token.secret
|
21
|
+
end
|
22
|
+
|
23
|
+
#######
|
24
|
+
private
|
25
|
+
#######
|
26
|
+
|
27
|
+
def consumer
|
28
|
+
@consumer ||= OAuth::Consumer.new(consumer_key, consumer_key_secret)
|
29
|
+
end
|
30
|
+
|
31
|
+
def xoauth_requestor_id
|
32
|
+
@xoauth_requestor_id ||= settings['xoauth_requestor_id']
|
33
|
+
end
|
34
|
+
|
35
|
+
def consumer_key
|
36
|
+
@consumer_key ||= settings['consumer_key']
|
37
|
+
end
|
38
|
+
|
39
|
+
def consumer_key_secret
|
40
|
+
@consumer_key_secret ||= settings['consumer_key_secret']
|
41
|
+
end
|
42
|
+
|
43
|
+
def settings
|
44
|
+
@fixtures ||= YAML.load_file(File.join(File.dirname(__FILE__), 'settings.yml'))
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "two-legged-oauth/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "two-legged-oauth"
|
7
|
+
s.version = TwoLeggedOAuth::VERSION
|
8
|
+
s.authors = ["Nikos Dimitrakopoulos"]
|
9
|
+
s.email = ["n.dimitrakopoulos@fraudpointer.com"]
|
10
|
+
s.homepage = "https://github.com/fraudpointer/two-legged-oauth-ruby"
|
11
|
+
s.summary = %q{Support for Google Apps 2 Legged OAuth}
|
12
|
+
s.description = %q{Extends the normal oauth gem to support Google's custom two legged OAuth (2LO) mechanism, needed for interacting with the Google Apps APIs through the Google Apps Marketplace.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "two-legged-oauth"
|
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
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_dependency("oauth", "~> 0.4.0")
|
23
|
+
s.add_development_dependency("bundler", ">= 1.0.0")
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: two-legged-oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nikos Dimitrakopoulos
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-03 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: oauth
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 4
|
33
|
+
- 0
|
34
|
+
version: 0.4.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
version: 1.0.0
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Extends the normal oauth gem to support Google's custom two legged OAuth (2LO) mechanism, needed for interacting with the Google Apps APIs through the Google Apps Marketplace.
|
54
|
+
email:
|
55
|
+
- n.dimitrakopoulos@fraudpointer.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- CHANGELOG.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/two-legged-oauth.rb
|
70
|
+
- lib/two-legged-oauth/access_token.rb
|
71
|
+
- lib/two-legged-oauth/version.rb
|
72
|
+
- test/access_token_test.rb
|
73
|
+
- test/settings.yml.example
|
74
|
+
- two-legged-oauth.gemspec
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: https://github.com/fraudpointer/two-legged-oauth-ruby
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project: two-legged-oauth
|
105
|
+
rubygems_version: 1.6.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Support for Google Apps 2 Legged OAuth
|
109
|
+
test_files:
|
110
|
+
- test/access_token_test.rb
|
111
|
+
- test/settings.yml.example
|