rb_goog_auth 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Gemfile +3 -0
  2. data/README.markdown +34 -0
  3. data/lib/rb_goog_auth.rb +36 -0
  4. metadata +69 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,34 @@
1
+ `rb_goog_auth`: Simple Google authentication
2
+ ==========
3
+
4
+ This gem wraps the old-fashioned Google "ClientLogin" authentication method. 99% of the time, you should use Google's OAuth APIs. Sometimes, however, you need to do things the old-fashioned way.
5
+
6
+ Installation
7
+ --------
8
+
9
+ gem install rb_goog_auth
10
+
11
+ Usage
12
+ --------
13
+
14
+ Given a Google account name, password, source, and service ID, the `GoogAuth` class will return SID, LSID, and Auth values. You probably just want to retain the Auth value.
15
+
16
+ For the love of all that is holy, _do not_ store the username and password in your application.
17
+
18
+ g = GoogAuth.new
19
+ c = g.get_credentials(:username => some_user_name, :password => some_password, :source => some_source, :service => some_service)
20
+ c.inspect # => {:sid => some_sid, :lsid => some_lsid, :auth => some_auth_token}
21
+
22
+ If authentication fails, `get_credentials` will return nil.
23
+
24
+ License
25
+ ----------
26
+ Copyright (c) 2012, Steven Bedrick
27
+ All rights reserved.
28
+
29
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
30
+
31
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
32
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
33
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
+
@@ -0,0 +1,36 @@
1
+ require "bundler/setup"
2
+ require 'typhoeus'
3
+
4
+ class GoogAuth
5
+
6
+ @@AUTH_URL = "https://www.google.com/accounts/ClientLogin"
7
+
8
+ def get_credentials(login_info)
9
+
10
+ email = login_info[:username]
11
+ password = login_info[:password]
12
+ source = login_info[:source]
13
+ serv = login_info[:service]
14
+
15
+ raise ArgumentError if [email, password, source, serv].include? nil
16
+ raise ArgumentError if [email, password, source, serv].include? ''
17
+
18
+ response = Typhoeus::Request.post(@@AUTH_URL, :params => {'Email' => email, 'Passwd' => password, 'source' => source, 'service' => serv})
19
+
20
+ return nil if response.code != 200
21
+
22
+ to_return = {}
23
+
24
+ response.body.split("\n").each do |l|
25
+ next if l.strip.nil? or l.strip.length == 0
26
+ k, v = l.strip.split("=")
27
+ to_return[k] = v
28
+ end
29
+
30
+ return to_return
31
+
32
+ end
33
+
34
+
35
+ end
36
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb_goog_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steven Bedrick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &2164482780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2164482780
25
+ - !ruby/object:Gem::Dependency
26
+ name: typhoeus
27
+ requirement: &2164481540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *2164481540
36
+ description:
37
+ email: steve@bedrick.org
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - Gemfile
43
+ - README.markdown
44
+ - lib/rb_goog_auth.rb
45
+ homepage: https://github.com/stevenbedrick/rb_goog_auth
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.10
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Simple Google authentication.
69
+ test_files: []