gpsoauth 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 204ea5290b6b19ac4b313ddc82c47b6a30f3924f
4
+ data.tar.gz: 261ff8ab1af1e678a6d94eeb6e90e99c409332df
5
+ SHA512:
6
+ metadata.gz: 5d562ca5ae735ff3662e0b5cf0ab9b0c2f10ed78ebcf099adc380b285639f88a906ecde2e63b0dd711202f1a1d4be55edb492b3a2f1a2b10f80e80e96f71677c
7
+ data.tar.gz: ea4eba98bfa330fb52108c292fcd84f0ec4c9c20fbc2f3de300900ca1505a7e05586f1db9146e60b931e05f6f4d3f39cacd93838acecddfaee2d653cf82a5041
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ *.swo
12
+ *.swp
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at [bryanmytko@gmail.com](http://github.com/bryanmytko). All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright(c) 2016 Bryan Mytko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Gpsoauth
2
+
3
+ A Ruby client library for Google Play Services OAuth
4
+
5
+ A port of the Python library [gpsoauth](https://github.com/simon-weber/gpsoauth) by [Simon Weber](https://github.com/simon-weber)
6
+
7
+ Android Play Service OAuth flow: [Sbktech](https://sbktech.blogspot.com/2014/01/inside-android-play-services-magic.html)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'gpsoauth'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install gpsoauth
24
+
25
+ ## Usage
26
+
27
+ Instantiate a Gpsoauth connection. This requires an Android ID:
28
+
29
+ g = Gpsoauth::Connection.new(android_id, [service, device_country, operator_country, lang, sdk_version])
30
+
31
+ Perform 'master login' with email/password:
32
+
33
+ response = g.master_login(email, password)
34
+
35
+ Use the response's token to perform the OAuth:
36
+
37
+ oauth_response = g.oauth(email, response["Token"], service, app, client_signature)
38
+
39
+ Access response Auth token via:
40
+
41
+ oauth_response["Auth"]
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bryanmytko/gpsoauth. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/gpsoauth.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gpsoauth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gpsoauth"
8
+ spec.version = Gpsoauth::VERSION
9
+ spec.authors = ["Bryan Mytko"]
10
+ spec.email = ["bryanmytko@gmail.com"]
11
+
12
+ spec.summary = %q{A Ruby client library for Google Play Services OAuth.}
13
+ spec.description = %q{A Ruby client library for Google Play Services OAuth.
14
+ A port of the Python library gpsoauth by Simon Weber}
15
+ spec.homepage = "http://github.com/bryanmytko/gpsoauth"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_dependency "httparty", "~> 0.13.7"
27
+ end
data/lib/gpsoauth.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "httparty"
2
+ require "base64"
3
+
4
+ require "gpsoauth/connection"
5
+ require "gpsoauth/exceptions"
6
+ require "gpsoauth/google"
7
+ require "gpsoauth/utility"
8
+ require "gpsoauth/version"
9
+
10
+ module Gpsoauth
11
+ include HTTParty
12
+ include Google
13
+ end
@@ -0,0 +1,86 @@
1
+ module Gpsoauth
2
+ class Connection
3
+ AUTH_URL = "https://android.clients.google.com/auth"
4
+ USER_AGENT = "gpsoauth/gpsoauth"
5
+
6
+ # The key is distirbuted with Google Play Services.
7
+ # This one is from version 7.3.29.
8
+ B64_KEY_7_3_29 = "AAAAgMom/1a/v0lblO2Ubrt60J2gcuXSljGFQXgcyZWveWLEwo6p" \
9
+ "rwgi3iJIZdodyhKZQrNWp5nKJ3srRXcUW+F1BD3baEVGcmEgqaLZUNBjm057pKRI16kB0" \
10
+ "YppeGx5qIQ5QjKzsR8ETQbKLNWgRY0QRNVz34kMJR3P/LgHax/6rmf5AAAAAwEAAQ==".b
11
+
12
+ def initialize(android_id, service = nil, device_country = nil,
13
+ operator_country = nil, lang = nil, sdk_version = nil)
14
+
15
+ @android_id = android_id
16
+
17
+ @service = service || "ac2dm"
18
+ @device_country = device_country || "us"
19
+ @operator_country = operator_country || "us"
20
+ @lang = lang || "en"
21
+ @sdk_version = sdk_version || 17
22
+ end
23
+
24
+ def master_login(email, password)
25
+ android_key = Google::key_from_b64(B64_KEY_7_3_29)
26
+
27
+ data = {
28
+ accountType: "HOSTED_OR_GOOGLE",
29
+ Email: email,
30
+ has_permission: 1,
31
+ add_account: 1,
32
+ # @TODO Finish password encryption
33
+ # EncryptedPasswd: Google::signature(email, password, android_key)
34
+ Passwd: password,
35
+ service: @service,
36
+ source: "android",
37
+ androidId: @android_id,
38
+ device_country: @device_country,
39
+ operatorCountry: @operator_country,
40
+ lang: @lang,
41
+ sdk_version: @sdk_version
42
+ }
43
+
44
+ auth_request(data)
45
+ end
46
+
47
+ def oauth(email, master_token, service, app, client_signature)
48
+ data = {
49
+ accountType: "HOSTED_OR_GOOGLE",
50
+ Email: email,
51
+ has_permission: 1,
52
+ EncryptedPasswd: master_token,
53
+ source: "android",
54
+ androidId: @android_id,
55
+ device_country: @device_country,
56
+ operatorCountry: @operator_country,
57
+ lang: @lang,
58
+ sdk_version: @sdk_version,
59
+ service: service,
60
+ app: app,
61
+ client_sig: client_signature
62
+ }
63
+
64
+ auth_request(data)
65
+ end
66
+
67
+ private
68
+
69
+ def auth_request(data)
70
+ options = {
71
+ body: data,
72
+ headers: {
73
+ "User-Agent" => USER_AGENT,
74
+ "Accept-Encoding" => ""
75
+ }
76
+ }
77
+
78
+ response = HTTParty.post(AUTH_URL, options)
79
+ parse_auth_response(response)
80
+ end
81
+
82
+ def parse_auth_response(response)
83
+ Hash[response.each_line.map { |l| l.chomp.split("=", 2) }]
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,4 @@
1
+ module Gpsoauth
2
+ class Error < StandardError; end
3
+ class NoAndroidIDError < Error; end
4
+ end
@@ -0,0 +1,42 @@
1
+ module Gpsoauth
2
+ module Google
3
+ def self.key_from_b64(key)
4
+ binary_key = Base64.decode64(key)
5
+
6
+ i = binary_key[0,4].sum
7
+ mod = binary_key[4, i].unpack("H*")[0].to_i(16)
8
+
9
+ j = binary_key[i + 4, 4].sum
10
+ exponent = binary_key[i + 8, j].unpack("H*")[0].to_i(16)
11
+
12
+ key = OpenSSL::PKey::RSA.new
13
+ key.e = OpenSSL::BN.new(exponent)
14
+ key.n = OpenSSL::BN.new(mod)
15
+
16
+ key
17
+ end
18
+
19
+ def self.signature(email, password, key)
20
+ signature = "\x00".bytes
21
+ struct = key_to_struct(key)
22
+ signature.push Digest::SHA1.hexdigest(struct)[0,4]
23
+
24
+ # @TODO Encryptedpasswd notes:
25
+ # http://codedigging.com/blog/2014-06-09-about-encryptedpasswd/
26
+ #
27
+ # cipher = PKCS1_OAEP.new(key)
28
+ # encrypted_login = cipher.encrypt((email + u'\x00' + password).encode('utf-8'))
29
+ # signature.extend(encrypted_login)
30
+ # return base64.urlsafe_b64encode(signature)
31
+ end
32
+
33
+ private
34
+
35
+ def self.key_to_struct(key)
36
+ mod = key.n.to_s.bytes.map{ |x| x.to_s(16) }.join
37
+ exponent = key.e.to_s.bytes.map{ |x| x.to_s(16) }.join
38
+
39
+ "\x00\x00\x00\x80#{mod}\x00\x00\x00\x03#{exponent}".b
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,2 @@
1
+ module Gpsoauth
2
+ end
@@ -0,0 +1,3 @@
1
+ module Gpsoauth
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gpsoauth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Mytko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-24 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.7
55
+ description: |-
56
+ A Ruby client library for Google Play Services OAuth.
57
+ A port of the Python library gpsoauth by Simon Weber
58
+ email:
59
+ - bryanmytko@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - gpsoauth.gemspec
70
+ - lib/gpsoauth.rb
71
+ - lib/gpsoauth/connection.rb
72
+ - lib/gpsoauth/exceptions.rb
73
+ - lib/gpsoauth/google.rb
74
+ - lib/gpsoauth/utility.rb
75
+ - lib/gpsoauth/version.rb
76
+ homepage: http://github.com/bryanmytko/gpsoauth
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A Ruby client library for Google Play Services OAuth.
100
+ test_files: []