minecraft_auth 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2135c15334aafbdb9cf72010c809a258abb35c9d
4
+ data.tar.gz: 233281db0244dd74dd3564f7ad970fbe4d3fbbb8
5
+ SHA512:
6
+ metadata.gz: d30913556795d960f16fda4ae882d2076f4186be4666d949072e64991a052b716d41f543b007aaed0a2d3c0bd739fc896fab8b7638d6e0651ec30491edc5f3a0
7
+ data.tar.gz: 1a4335aecf3844aac0fd54eb9e8c9ca1bc2f68ade7b30b51c8311395cb154e992d890020e8d710013c8d6fadd912de2e42127e853b370480514d555dd978bdbe
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in minecraft_auth.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jake
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # MinecraftAuth
2
+
3
+ A Ruby gem for testing Minecraft account authentication.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'minecraft_auth'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install minecraft_auth
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'minecraft_auth'
25
+ account = MinecraftAuth.account('Jake0oo0', 'xXPasswordXx')
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/Jake0oo0/minecraft_auth/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,70 @@
1
+ require "minecraft_auth/version"
2
+ require 'httparty'
3
+
4
+ module MinecraftAuth
5
+ PROTOCOL = "https://"
6
+ BASE_URL = "authserver.mojang.com"
7
+ ENDPOINT = "/authenticate"
8
+
9
+ def self.account(user, pass)
10
+ Account.new(user, pass)
11
+ end
12
+
13
+ class Account
14
+ attr_reader :username
15
+ attr_reader :password
16
+ attr_reader :access_token
17
+ attr_reader :client_token
18
+ attr_reader :profiles
19
+
20
+ def initialize(username, password)
21
+ @username = username
22
+ @password = password
23
+
24
+ response = HTTParty.post("#{PROTOCOL}#{BASE_URL}#{ENDPOINT}",
25
+ :body => {
26
+ :"agent" => {
27
+ :"name" => "Minecraft",
28
+ :"version" => 1
29
+ },
30
+ :"username" => "#{@username}",
31
+ :"password" => "#{@password}"
32
+ }.to_json,
33
+ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
34
+ )
35
+ # No Error
36
+ if not response['error']
37
+ @access_token = response['accessToken']
38
+ @client_token = response['clientToken']
39
+ raw_profiles = response['availableProfiles']
40
+ raw_selected = response['selectedProfile']
41
+ @profiles = Array.new
42
+ raw_profiles.each do |profile|
43
+ selected = raw_selected['name'] == profile['name'] and raw_selected['id'] == profile['id']
44
+ @profiles << Profile.new(profile['name'], profile['id'], selected)
45
+ end
46
+ # Error in response
47
+ else
48
+ raise AccountError, response["errorMessage"]
49
+ end
50
+ end
51
+ end
52
+
53
+ class Profile
54
+ attr_reader :name
55
+ attr_reader :id
56
+ attr_reader :selected
57
+
58
+ def initialize(name, id, selected)
59
+ @id = id
60
+ @name = name
61
+ @selected = selected
62
+ end
63
+ end
64
+
65
+ class AccountError < StandardError
66
+ def initialize(message)
67
+ super()
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module MinecraftAuth
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'minecraft_auth/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "minecraft_auth"
8
+ spec.version = MinecraftAuth::VERSION
9
+ spec.authors = ["Jake"]
10
+ spec.email = ["jake0oo0dev@gmail.com"]
11
+ spec.summary = %q{A ruby gem for Minecraft account authentication.}
12
+ spec.description = %q{A ruby gem for Minecraft account authentication.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.1'
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'minecraft_auth'
3
+
4
+ class AccountTest < Test::Unit::TestCase
5
+ def test_failure
6
+ assert_raise MinecraftAuth::AccountError do
7
+ MinecraftAuth.account('BadUser', 'BadPassword')
8
+ end
9
+ end
10
+
11
+ # This can be tested if necessary, otherwise credentials should remain private.
12
+ # def test_valid
13
+ # assert_raise MinecraftAuth::AccountError do
14
+ # MinecraftAuth.account('GoodUser', 'GoodPassword')
15
+ # end
16
+ # end
17
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minecraft_auth
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jake
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-15 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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'
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: 0.13.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: '0.13'
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 0.13.1
61
+ description: A ruby gem for Minecraft account authentication.
62
+ email:
63
+ - jake0oo0dev@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - lib/minecraft_auth.rb
74
+ - lib/minecraft_auth/version.rb
75
+ - minecraft_auth.gemspec
76
+ - test/test_account.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.4.1
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A ruby gem for Minecraft account authentication.
101
+ test_files:
102
+ - test/test_account.rb