gmail_xoauth 0.4.1 → 0.4.2
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 +7 -0
- data/README.markdown +9 -8
- data/lib/gmail_xoauth/smtp_xoauth2_authenticator.rb +21 -4
- data/lib/gmail_xoauth/version.rb +2 -2
- data/test/helper.rb +1 -1
- data/test/test_smtp_xoauth2_authenticator.rb +26 -0
- metadata +29 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ada8e1bb60133f9f4e64470edfb71d6d3088c11f
|
4
|
+
data.tar.gz: c1ad5cd94d78ce593d9bfbefc7d74e8261960728
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 485c6cf1092f97c72b8e0482faab12d0f8cff92c06080ac5026eb82054dd8fef2f9592d6f0a40258e249cd6ddfe395e89498e7f99c1b9d1b8962079a315fa022
|
7
|
+
data.tar.gz: d89e40b5c4d6fd08b5347f669a9f27ba81ad12f6c680b6415631580cc9e65b796230567e660ea581926a3939a9ba68f42b286b211f91627dc6992246cc5dddad
|
data/README.markdown
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# gmail_xoauth [](https://gemnasium.com/nfo/gmail_xoauth)
|
1
|
+
# gmail_xoauth [](http://badge.fury.io/rb/gmail_xoauth) [](https://gemnasium.com/nfo/gmail_xoauth)
|
2
2
|
|
3
3
|
Get access to [Gmail IMAP and STMP via OAuth2](https://developers.google.com/google-apps/gmail/xoauth2_protocol) and [OAuth 1.0a](https://developers.google.com/google-apps/gmail/oauth_protocol), using the standard Ruby Net libraries.
|
4
4
|
|
@@ -14,9 +14,11 @@ The gem supports 3-legged OAuth, and 2-legged OAuth for Google Apps Business or
|
|
14
14
|
|
15
15
|
You can generate and validate your OAuth 2.0 tokens thanks to the [oauth2.py tool](http://code.google.com/p/google-mail-oauth2-tools/wiki/OAuth2DotPyRunThrough).
|
16
16
|
|
17
|
-
Create your API project in the [Google APIs console](https://code.google.com/apis/console/), from the "
|
17
|
+
Create your API project in the [Google APIs console](https://code.google.com/apis/console/), from the menu "APIs and auth > Credentials". Click on "Create new Client ID", choose "Installed Application" and "Other".
|
18
18
|
|
19
|
-
|
19
|
+
Then go to the menu "APIs and auth > Consent screen" and enter an email address and product name.
|
20
|
+
|
21
|
+
$ python oauth2.py --generate_oauth2_token --client_id=423906513574-o9v6kqt89lefrbfv1f3394u9rebfgv6n.apps.googleusercontent.com --client_secret=5SfdvZsYagblukE5VAhERjxZ
|
20
22
|
|
21
23
|
### IMAP OAuth 2.0
|
22
24
|
|
@@ -118,14 +120,13 @@ smtp.finish
|
|
118
120
|
|
119
121
|
## Compatibility
|
120
122
|
|
121
|
-
Tested on Ruby MRI 1.8.6, 1.8.7, 1.9.
|
123
|
+
Tested on Ruby MRI 1.8.6, 1.8.7, 1.9.x and 2.1.x. Feel free to send me a message if you tested this code with other implementations of Ruby.
|
122
124
|
|
123
125
|
The only external dependency is the [oauth gem](http://rubygems.org/gems/oauth).
|
124
126
|
|
125
127
|
## History
|
126
128
|
|
127
|
-
* 0.4.1
|
128
|
-
* 0.4.0 [XOAUTH2](https://developers.google.com/google-apps/gmail/xoauth2_protocol) support, thanks to [glongman](https://github.com/glongman)
|
129
|
+
* 0.4.1 [XOAUTH2](https://developers.google.com/google-apps/gmail/xoauth2_protocol) support, thanks to [glongman](https://github.com/glongman)
|
129
130
|
* 0.3.2 New email for the maintainer
|
130
131
|
* 0.3.1 2-legged OAuth support confirmed by [BobDohnal](https://github.com/BobDohnal)
|
131
132
|
* 0.3.0 Experimental 2-legged OAuth support, thanks to [wojciech](https://github.com/wojciech)
|
@@ -133,7 +134,7 @@ The only external dependency is the [oauth gem](http://rubygems.org/gems/oauth).
|
|
133
134
|
* 0.1.0 Initial release with IMAP support and 3-legged OAuth
|
134
135
|
|
135
136
|
## Note on Patches/Pull Requests
|
136
|
-
|
137
|
+
|
137
138
|
* Fork the project.
|
138
139
|
* Make your feature addition or bug fix.
|
139
140
|
* Add tests for it. This is important so I don't break it in a
|
@@ -148,4 +149,4 @@ http://about.me/nfo
|
|
148
149
|
|
149
150
|
## License
|
150
151
|
|
151
|
-
See LICENSE for details.
|
152
|
+
See LICENSE for details.
|
@@ -3,14 +3,31 @@ require 'base64'
|
|
3
3
|
|
4
4
|
module GmailXoauth
|
5
5
|
module SmtpXoauth2Authenticator
|
6
|
-
|
6
|
+
|
7
|
+
def send_xoauth2(auth_token)
|
8
|
+
critical {
|
9
|
+
get_response("AUTH XOAUTH2 #{auth_token}")
|
10
|
+
}
|
11
|
+
end
|
12
|
+
private :send_xoauth2
|
13
|
+
|
14
|
+
def get_final_status
|
15
|
+
critical {
|
16
|
+
get_response("")
|
17
|
+
}
|
18
|
+
end
|
19
|
+
private :get_final_status
|
20
|
+
|
7
21
|
def auth_xoauth2(user, oauth2_token)
|
8
22
|
check_auth_args user, oauth2_token
|
9
23
|
|
10
24
|
auth_string = build_oauth2_string(user, oauth2_token)
|
11
|
-
res =
|
12
|
-
|
13
|
-
|
25
|
+
res = send_xoauth2(base64_encode(auth_string))
|
26
|
+
|
27
|
+
# See note about SMTP protocol exchange in https://developers.google.com/gmail/xoauth2_protocol
|
28
|
+
if res.continue?
|
29
|
+
res = get_final_status
|
30
|
+
end
|
14
31
|
|
15
32
|
check_auth_response res
|
16
33
|
res
|
data/lib/gmail_xoauth/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module GmailXoauth
|
2
|
-
VERSION = "0.4.
|
3
|
-
end
|
2
|
+
VERSION = "0.4.2"
|
3
|
+
end
|
data/test/helper.rb
CHANGED
@@ -29,4 +29,30 @@ class TestSmtpXoauthAuthenticator < Test::Unit::TestCase
|
|
29
29
|
ensure
|
30
30
|
smtp.finish if smtp && smtp.started?
|
31
31
|
end
|
32
|
+
|
33
|
+
# Test the handling of 3xx response to an "AUTH XOAUTH2" request... client
|
34
|
+
# should send a "\r\n" to get the actual error that occurred.
|
35
|
+
#
|
36
|
+
# See note about SMTP protocol exchange in https://developers.google.com/
|
37
|
+
# gmail/xoauth2_protocol
|
38
|
+
#
|
39
|
+
def test_authenticate_with_continuation
|
40
|
+
smtp = Net::SMTP.new('smtp.gmail.com', 587)
|
41
|
+
|
42
|
+
# Stub return from initial "AUTH XOAUTH2" request as well as the empty line sent to get final error
|
43
|
+
smtp.stubs(:send_xoauth2).returns(Net::SMTP::Response.parse("334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ=="))
|
44
|
+
smtp.stubs(:get_final_status).returns(Net::SMTP::Response.parse("454 4.7.0 Too many login attempts, please try again later. j63sm3521185itj.19 - gsmtp"))
|
45
|
+
|
46
|
+
smtp.enable_starttls_auto
|
47
|
+
|
48
|
+
# Validate an error is still raised
|
49
|
+
ex = assert_raise(Net::SMTPAuthenticationError) do
|
50
|
+
smtp.start('gmail.com', 'roger@moore.com', 'a', :xoauth2)
|
51
|
+
end
|
52
|
+
|
53
|
+
# ...and that the 334 is not passed back to the caller.
|
54
|
+
assert_equal("454 4.7.0 Too many login attempts, please try again later. j63sm3521185itj.19 - gsmtp", ex.message)
|
55
|
+
ensure
|
56
|
+
smtp.finish if smtp && smtp.started?
|
57
|
+
end
|
32
58
|
end
|
metadata
CHANGED
@@ -1,46 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gmail_xoauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nicolas Fouché
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: oauth
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.3.6
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.3.6
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: shoulda
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocha
|
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
|
+
- - ">="
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
description: Get access to Gmail IMAP and STMP via OAuth, using the standard Ruby
|
@@ -51,45 +60,44 @@ executables: []
|
|
51
60
|
extensions: []
|
52
61
|
extra_rdoc_files: []
|
53
62
|
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.markdown
|
65
|
+
- lib/gmail_xoauth.rb
|
54
66
|
- lib/gmail_xoauth/imap_xoauth2_authenticator.rb
|
55
67
|
- lib/gmail_xoauth/imap_xoauth_authenticator.rb
|
56
68
|
- lib/gmail_xoauth/oauth_string.rb
|
57
69
|
- lib/gmail_xoauth/smtp_xoauth2_authenticator.rb
|
58
70
|
- lib/gmail_xoauth/smtp_xoauth_authenticator.rb
|
59
71
|
- lib/gmail_xoauth/version.rb
|
60
|
-
- lib/gmail_xoauth.rb
|
61
72
|
- test/helper.rb
|
62
73
|
- test/test_imap_xoauth2_authenticator.rb
|
63
74
|
- test/test_imap_xoauth_authenticator.rb
|
64
75
|
- test/test_oauth_string.rb
|
65
76
|
- test/test_smtp_xoauth2_authenticator.rb
|
66
77
|
- test/test_smtp_xoauth_authenticator.rb
|
67
|
-
- LICENSE
|
68
|
-
- README.markdown
|
69
78
|
homepage: https://github.com/nfo/gmail_xoauth
|
70
79
|
licenses: []
|
80
|
+
metadata: {}
|
71
81
|
post_install_message:
|
72
82
|
rdoc_options:
|
73
|
-
- --charset=UTF-8
|
83
|
+
- "--charset=UTF-8"
|
74
84
|
require_paths:
|
75
85
|
- lib
|
76
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
87
|
requirements:
|
79
|
-
- -
|
88
|
+
- - ">="
|
80
89
|
- !ruby/object:Gem::Version
|
81
90
|
version: '0'
|
82
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
-
none: false
|
84
92
|
requirements:
|
85
|
-
- -
|
93
|
+
- - ">="
|
86
94
|
- !ruby/object:Gem::Version
|
87
95
|
version: 1.3.6
|
88
96
|
requirements: []
|
89
97
|
rubyforge_project:
|
90
|
-
rubygems_version:
|
98
|
+
rubygems_version: 2.4.5.1
|
91
99
|
signing_key:
|
92
|
-
specification_version:
|
100
|
+
specification_version: 4
|
93
101
|
summary: Get access to Gmail IMAP and STMP via OAuth, using the standard Ruby Net
|
94
102
|
libraries
|
95
103
|
test_files: []
|