gmail_xoauth 0.4.1 → 0.4.3

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
+ SHA256:
3
+ metadata.gz: a128d4dd6159a1ceaeb6415c6cf0956e358e5752cca94617896f851ecdd71587
4
+ data.tar.gz: 2d89b9a0d67b700fdfafb5bec9d2af4f16404bd07a606b221afd508d072dc258
5
+ SHA512:
6
+ metadata.gz: 7f20d1e04affcc7e5c4f239bc44d7534aa20d6b5752b0751367a5087566b61b882c169c6e10342f5d01f04eb67fbc0c695ad781ca9c814783483d54fa5112b10
7
+ data.tar.gz: 43c1ce7b6de2095bb826c4815fa44758534b404762cf83ac99690da24c7566da508378921caaf6544babc4712c9a3cca6cfb4d9b1708ad3f802e5a08f8422c7d
data/LICENSE CHANGED
@@ -1,14 +1,24 @@
1
- Author: Nicolas Fouché <nicolas.fouche@gmail.com>
2
- Copyright: (C) 2011 Silentale SAS
1
+ This is free and unencumbered software released into the public domain.
3
2
 
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
7
 
8
- http://www.apache.org/licenses/LICENSE-2.0
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
9
15
 
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
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 NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
- # gmail_xoauth [![Dependency Status](https://gemnasium.com/nfo/gmail_xoauth.png)](https://gemnasium.com/nfo/gmail_xoauth)
1
+ # gmail_xoauth [![Gem Version](https://badge.fury.io/rb/gmail_xoauth.png)](http://badge.fury.io/rb/gmail_xoauth)
2
2
 
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.
3
+ Get access to [Gmail IMAP and SMTP 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
 
5
5
  The gem supports 3-legged OAuth, and 2-legged OAuth for Google Apps Business or Education account owners.
6
6
 
@@ -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 "API Access" tab.
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
- $ python oauth2.py --generate_oauth2_token --client_id=364545978226.apps.googleusercontent.com --client_secret=zNrNsBzOOnQy8_O-8LkofeTR
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,15 @@ smtp.finish
118
120
 
119
121
  ## Compatibility
120
122
 
121
- Tested on Ruby MRI 1.8.6, 1.8.7, 1.9.1, 1.9.2 and 1.9.3. Feel free to send me a message if you tested this code with other implementations of Ruby.
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 Changed to way to give the OAuth 2.0 token, see https://github.com/nfo/gmail_xoauth/commit/b7b936cfb094c2fc9b8e9e48526906191423cb88
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.3 Maintenance: Use Net::IMAP::SASL.add_authenticator to silence deprecation warning, thanks to [mantas](https://github.com/mantas)
130
+ * 0.4.2 SMTP: on 3xx response to 'AUTH XOAUTH2' send CR-LF to get actual error, thanks to [rafalyesware](https://github.com/rafalyesware)
131
+ * 0.4.1 [XOAUTH2](https://developers.google.com/google-apps/gmail/xoauth2_protocol) support, thanks to [glongman](https://github.com/glongman)
129
132
  * 0.3.2 New email for the maintainer
130
133
  * 0.3.1 2-legged OAuth support confirmed by [BobDohnal](https://github.com/BobDohnal)
131
134
  * 0.3.0 Experimental 2-legged OAuth support, thanks to [wojciech](https://github.com/wojciech)
@@ -133,7 +136,7 @@ The only external dependency is the [oauth gem](http://rubygems.org/gems/oauth).
133
136
  * 0.1.0 Initial release with IMAP support and 3-legged OAuth
134
137
 
135
138
  ## Note on Patches/Pull Requests
136
-
139
+
137
140
  * Fork the project.
138
141
  * Make your feature addition or bug fix.
139
142
  * Add tests for it. This is important so I don't break it in a
@@ -144,8 +147,8 @@ The only external dependency is the [oauth gem](http://rubygems.org/gems/oauth).
144
147
 
145
148
  ## Contact me
146
149
 
147
- http://about.me/nfo
150
+ https://nicolasfouche.com
148
151
 
149
152
  ## License
150
153
 
151
- See LICENSE for details.
154
+ See LICENSE for details.
@@ -21,4 +21,8 @@ module GmailXoauth
21
21
  end
22
22
  end
23
23
 
24
- Net::IMAP.add_authenticator('XOAUTH2', GmailXoauth::ImapXoauth2Authenticator)
24
+ if Net::IMAP.const_defined?('SASL') && Net::IMAP::SASL.respond_to?(:add_authenticator)
25
+ Net::IMAP::SASL.add_authenticator('XOAUTH2', GmailXoauth::ImapXoauth2Authenticator)
26
+ else
27
+ Net::IMAP.add_authenticator('XOAUTH2', GmailXoauth::ImapXoauth2Authenticator)
28
+ end
@@ -28,4 +28,8 @@ module GmailXoauth
28
28
  end
29
29
  end
30
30
 
31
- Net::IMAP.add_authenticator('XOAUTH', GmailXoauth::ImapXoauthAuthenticator)
31
+ if Net::IMAP.const_defined?('SASL') && Net::IMAP::SASL.respond_to?(:add_authenticator)
32
+ Net::IMAP::SASL.add_authenticator('XOAUTH', GmailXoauth::ImapXoauthAuthenticator)
33
+ else
34
+ Net::IMAP.add_authenticator('XOAUTH', GmailXoauth::ImapXoauthAuthenticator)
35
+ end
@@ -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 = critical {
12
- get_response("AUTH XOAUTH2 #{base64_encode(auth_string)}")
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
@@ -1,3 +1,3 @@
1
1
  module GmailXoauth
2
- VERSION = "0.4.1"
3
- end
2
+ VERSION = "0.4.3"
3
+ end
data/test/helper.rb CHANGED
@@ -2,7 +2,7 @@ require 'yaml'
2
2
 
3
3
  require 'rubygems'
4
4
  require 'test/unit'
5
- require 'mocha'
5
+ require 'mocha/test_unit'
6
6
 
7
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -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.1
5
- prerelease:
4
+ version: 0.4.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nicolas Fouché
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-16 00:00:00.000000000 Z
11
+ date: 2024-01-17 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,43 @@ 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
- rubyforge_project:
90
- rubygems_version: 1.8.23
97
+ rubygems_version: 3.0.3.1
91
98
  signing_key:
92
- specification_version: 3
99
+ specification_version: 4
93
100
  summary: Get access to Gmail IMAP and STMP via OAuth, using the standard Ruby Net
94
101
  libraries
95
102
  test_files: []