Comparing version 0.1.0 to 0.2.0
/* jshint node: true */ | ||
"use strict"; | ||
'use strict'; | ||
var crypto = require('crypto'); | ||
@@ -11,3 +11,3 @@ var assert = require('assert'); | ||
var config = { | ||
host : con.host || "https://authserver.mojang.com" //Allow for a custom auth server | ||
host : con.host || 'https://authserver.mojang.com' //Allow for a custom auth server | ||
}; | ||
@@ -17,4 +17,4 @@ | ||
headers: { | ||
"User-Agent" : "node-yggdrasil/" + version, | ||
"Content-Type" : "application/json" | ||
'User-Agent' : 'node-yggdrasil/' + version, | ||
'Content-Type' : 'application/json' | ||
} | ||
@@ -27,8 +27,7 @@ }); | ||
method: 'POST', | ||
uri: config.host + "/" + path, | ||
uri: config.host + '/' + path, | ||
json: data | ||
}, function (err, resp, body) { | ||
if (body && body.error) { | ||
var out = body.errorMessage; | ||
cb(out); | ||
cb(new Error(body.errorMessage)); | ||
} else { | ||
@@ -52,7 +51,7 @@ cb(err, body); | ||
options.agent = options.agent || "Minecraft"; | ||
options.agent = options.agent || 'Minecraft'; | ||
r._call('authenticate', { | ||
agent : { | ||
name: options.agent, | ||
version : options.agent === "Minecraft" ? 1 : options.version | ||
version : options.agent === 'Minecraft' ? 1 : options.version | ||
}, | ||
@@ -78,6 +77,7 @@ username: options.user, | ||
}, function (err, data) { | ||
if (data.clientToken !== client) { | ||
cb("clientToken assertion failed"); | ||
if (err) cb(err); | ||
if (data && data.clientToken !== client) { | ||
cb(new Error('clientToken assertion failed')); | ||
} else { | ||
cb(null, data.accessToken, data); | ||
cb(err, data ? data.accessToken : null, data); | ||
} | ||
@@ -90,3 +90,3 @@ }); | ||
* @param {String} token Token to validate | ||
* @param {Function} cb (is okay, error) | ||
* @param {Function} cb (error) | ||
*/ | ||
@@ -97,7 +97,3 @@ r.validate = function (token, cb) { | ||
}, function (err, data) { | ||
if (err) { | ||
cb(false, err); | ||
} else { | ||
cb(true); | ||
} | ||
cb(err); | ||
}); | ||
@@ -109,3 +105,3 @@ }; | ||
* @param {String} pass User's pass | ||
* @param {Function} cb (worked, error) | ||
* @param {Function} cb (error) | ||
*/ | ||
@@ -117,7 +113,3 @@ r.signout = function (user, pass, cb) { | ||
}, function (err, data) { | ||
if (err) { | ||
cb(false, err); | ||
} else { | ||
cb(true); | ||
} | ||
cb(err); | ||
}); | ||
@@ -132,3 +124,3 @@ }; | ||
var config = { | ||
host : con.host || "https://sessionserver.mojang.com" //Allow for a custom auth server | ||
host : con.host || 'https://sessionserver.mojang.com' //Allow for a custom auth server | ||
}; | ||
@@ -138,4 +130,4 @@ | ||
headers: { | ||
"User-Agent" : "node-yggdrasil/" + version, | ||
"Content-Type" : "application/json" | ||
'User-Agent' : 'node-yggdrasil/' + version, | ||
'Content-Type' : 'application/json' | ||
} | ||
@@ -148,8 +140,7 @@ }); | ||
method: 'POST', | ||
uri: config.host + "/" + path, | ||
uri: config.host + '/' + path, | ||
json: data | ||
}, function (err, resp, body) { | ||
if (body && body.error) { | ||
var out = body.errorMessage; | ||
cb(out); | ||
cb(new Error(body.errorMessage)); | ||
} else { | ||
@@ -215,5 +206,5 @@ cb(err, body); | ||
r._call('session/minecraft/join', { | ||
"accessToken": token, | ||
"selectedProfile": profile, | ||
"serverId": r.mcHexDigest(crypto.createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest()) | ||
'accessToken': token, | ||
'selectedProfile': profile, | ||
'serverId': r.mcHexDigest(crypto.createHash('sha1').update(serverid).update(sharedsecret).update(serverkey).digest()) | ||
}, function(err, data) { | ||
@@ -242,6 +233,6 @@ cb(err, data); | ||
cb(err, body); | ||
} else if (body && body.hasOwnProperty("id")) { // Success | ||
} else if (body && body.hasOwnProperty('id')) { // Success | ||
cb(err, body); | ||
} else { | ||
cb(new Error("Failed to verify username!")); | ||
cb(new Error('Failed to verify username!')); | ||
} | ||
@@ -248,0 +239,0 @@ }); |
{ | ||
"name": "yggdrasil", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Zeke Sonxx <zeke@zekesonxx.com>", | ||
@@ -24,4 +24,4 @@ "description": "Mojang authentication (Yggdrasil) client", | ||
"dependencies": { | ||
"request": "~2.34.0", | ||
"uuid": "~1.4.1" | ||
"request": "~2.78.0", | ||
"uuid": "~2.0.3" | ||
}, | ||
@@ -28,0 +28,0 @@ "license": "MIT", |
# yggdrasil | ||
[![Build Status](http://img.shields.io/travis/zekesonxx/node-yggdrasil.svg)](https://travis-ci.org/zekesonxx/node-yggdrasil) | ||
[![NPM Link](https://img.shields.io/npm/v/yggdrasil.svg?style=plastic)](https://www.npmjs.com/package/yggdrasil) | ||
[![Build Status](http://img.shields.io/travis/zekesonxx/node-yggdrasil.svg?style=plastic)](https://travis-ci.org/zekesonxx/node-yggdrasil) | ||
@@ -7,2 +8,5 @@ A Node.js client for doing requests to yggdrasil, the Mojang authentication system, used for Minecraft and Scrolls. | ||
node-yggdrasil was originally made because I was messing around with trying to make a Minecraft server in JS. Never really got anywhere with it. | ||
However, the folks over at [PrismarineJS](https://github.com/PrismarineJS/) have gotten quite far with it, and use this library in their project. | ||
# Usage | ||
@@ -32,6 +36,6 @@ $ npm install yggdrasil | ||
//Validate an accessToken | ||
ygg.validate(token, function(isvalid, err){}); | ||
ygg.validate(token, function(err){}); | ||
//Invalidate all accessTokens | ||
ygg.signout(username, password, function(worked, err)); | ||
ygg.signout(username, password, function(err)); | ||
``` | ||
@@ -57,2 +61,2 @@ | ||
* [node-minecraft-protocol](https://github.com/PrismarineJS/node-minecraft-protocol), a Minecraft client and server in Node.js | ||
* [prismarine-yggdrasil](https://github.com/PrismarineJS/prismarine-yggdrasil), another yggdrasil client that node-yggdrasil [will be replacing](https://github.com/PrismarineJS/prismarine-yggdrasil/issues/2). | ||
* [prismarine-yggdrasil](https://github.com/PrismarineJS/prismarine-yggdrasil), another yggdrasil client that node-yggdrasil replaced (issue links: [prismarine-yggdrasil #2](https://github.com/PrismarineJS/prismarine-yggdrasil/issues/2), [node-minecraft-protocol #117](https://github.com/PrismarineJS/node-minecraft-protocol/issues/117)). |
@@ -14,3 +14,3 @@ /* jshint node: true, expr: true */ | ||
cake: true, | ||
username: "someone" | ||
username: 'someone' | ||
}; | ||
@@ -26,8 +26,9 @@ scope.post('/test', {}).reply(200, bsdata); | ||
scope.post('/test2', {}).reply(200, { | ||
error: "ThisBeAError", | ||
errorMessage: "Yep, you failed." | ||
error: 'ThisBeAError', | ||
errorMessage: 'Yep, you failed.' | ||
}); | ||
ygg._call('test2', {}, function (err, data) { | ||
should(data).be.undefined; | ||
err.should.equal("Yep, you failed."); | ||
err.should.be.an.instanceOf(Error); | ||
err.message.should.equal('Yep, you failed.'); | ||
done(); | ||
@@ -42,7 +43,7 @@ }); | ||
version: 1, | ||
name: "Minecraft" | ||
name: 'Minecraft' | ||
}, | ||
username: "cake", | ||
password: "hunter2", | ||
clientToken: "bacon" | ||
username: 'cake', | ||
password: 'hunter2', | ||
clientToken: 'bacon' | ||
}).reply(200, { | ||
@@ -52,5 +53,5 @@ worked: true | ||
ygg.auth({ | ||
user: "cake", | ||
pass: "hunter2", | ||
token: "bacon" | ||
user: 'cake', | ||
pass: 'hunter2', | ||
token: 'bacon' | ||
}, function (err, data) { | ||
@@ -67,11 +68,11 @@ data.should.eql({ | ||
scope.post('/refresh', { | ||
accessToken: "bacon", | ||
clientToken: "not bacon" | ||
accessToken: 'bacon', | ||
clientToken: 'not bacon' | ||
}).reply(200, { | ||
accessToken: "different bacon", | ||
clientToken: "not bacon" | ||
accessToken: 'different bacon', | ||
clientToken: 'not bacon' | ||
}); | ||
ygg.refresh("bacon", "not bacon", function (err, token) { | ||
ygg.refresh('bacon', 'not bacon', function (err, token) { | ||
should(err).be.undefined; | ||
token.should.equal("different bacon"); | ||
token.should.equal('different bacon'); | ||
done(); | ||
@@ -82,11 +83,12 @@ }); | ||
scope.post('/refresh', { | ||
accessToken: "bacon", | ||
clientToken: "not bacon" | ||
accessToken: 'bacon', | ||
clientToken: 'not bacon' | ||
}).reply(200, { | ||
accessToken: "different bacon", | ||
clientToken: "bacon" | ||
accessToken: 'different bacon', | ||
clientToken: 'bacon' | ||
}); | ||
ygg.refresh("bacon", "not bacon", function (err, token) { | ||
ygg.refresh('bacon', 'not bacon', function (err, token) { | ||
should(token).be.undefined; | ||
err.should.equal("clientToken assertion failed"); | ||
err.should.be.an.instanceOf(Error); | ||
err.message.should.equal('clientToken assertion failed'); | ||
done(); | ||
@@ -97,8 +99,7 @@ }); | ||
describe ('validate', function () { | ||
it ('should return true on valid response', function (done) { | ||
it ('should return undefined on valid response', function (done) { | ||
scope.post('/validate', { | ||
accessToken: "a magical key" | ||
accessToken: 'a magical key' | ||
}).reply(200); | ||
ygg.validate("a magical key", function (okay, err) { | ||
okay.should.be.true; | ||
ygg.validate('a magical key', function (err) { | ||
should(err).be.undefined; | ||
@@ -108,12 +109,12 @@ done(); | ||
}); | ||
it ('should return false on an error', function (done) { | ||
it ('should return Error on error', function (done) { | ||
scope.post('/validate', { | ||
accessToken: "a magical key" | ||
accessToken: 'a magical key' | ||
}).reply(403, { | ||
error: "UserEggError", | ||
errorMessage: "User is an egg" | ||
error: 'UserEggError', | ||
errorMessage: 'User is an egg' | ||
}); | ||
ygg.validate("a magical key", function (okay, err) { | ||
okay.should.be.false; | ||
err.should.equal("User is an egg"); | ||
ygg.validate('a magical key', function (err) { | ||
err.should.be.an.instanceOf(Error); | ||
err.message.should.equal('User is an egg'); | ||
done(); | ||
@@ -138,3 +139,3 @@ }); | ||
cake: true, | ||
username: "someone" | ||
username: 'someone' | ||
}; | ||
@@ -150,8 +151,9 @@ sscope.post('/test', {}).reply(200, bsdata); | ||
sscope.post('/test2', {}).reply(200, { | ||
error: "ThisBeAError", | ||
errorMessage: "Yep, you failed." | ||
error: 'ThisBeAError', | ||
errorMessage: 'Yep, you failed.' | ||
}); | ||
yggserver._call('test2', {}, function (err, data) { | ||
should(data).be.undefined; | ||
err.should.equal("Yep, you failed."); | ||
err.should.be.an.instanceOf(Error); | ||
err.message.should.equal('Yep, you failed.'); | ||
done(); | ||
@@ -180,5 +182,5 @@ }); | ||
sscope.post('/session/minecraft/join', { | ||
"accessToken": 'anAccessToken', | ||
"selectedProfile": 'aSelectedProfile', | ||
"serverId": '-af59e5b1d5d92e5c2c2776ed0e65e90be181f2a' | ||
'accessToken': 'anAccessToken', | ||
'selectedProfile': 'aSelectedProfile', | ||
'serverId': '-af59e5b1d5d92e5c2c2776ed0e65e90be181f2a' | ||
}).reply(200, { | ||
@@ -188,3 +190,3 @@ worked: true | ||
yggserver.join("anAccessToken", "aSelectedProfile", "cat", "cat", "cat", function (err, data) { | ||
yggserver.join('anAccessToken', 'aSelectedProfile', 'cat', 'cat', 'cat', function (err, data) { | ||
data.should.eql({ | ||
@@ -205,3 +207,3 @@ worked: true | ||
yggserver.hasJoined("ausername", "cat", "cat", "cat", function (err, data) { | ||
yggserver.hasJoined('ausername', 'cat', 'cat', 'cat', function (err, data) { | ||
if (err) return done(err); | ||
@@ -218,4 +220,4 @@ data.should.eql({ | ||
yggserver.hasJoined("ausername", "cat", "cat", "cat", function (err, data) { | ||
err.should.be.an.Error; | ||
yggserver.hasJoined('ausername', 'cat', 'cat', 'cat', function (err, data) { | ||
err.should.be.an.instanceOf(Error); | ||
done(); | ||
@@ -222,0 +224,0 @@ }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17349
60
415
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@0.2.01.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.6.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedboom@2.10.1(transitive)
+ Addedcaseless@0.11.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addedcryptiles@2.0.5(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.1.4(transitive)
+ Addedgenerate-function@2.3.1(transitive)
+ Addedgenerate-object-property@1.2.0(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-validator@2.0.6(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhawk@3.1.3(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.1.1(transitive)
+ Addedis-my-ip-valid@1.0.1(transitive)
+ Addedis-my-json-valid@2.20.6(transitive)
+ Addedis-property@1.0.2(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjsonpointer@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.8.2(transitive)
+ Addedpinkie@2.0.4(transitive)
+ Addedpinkie-promise@2.0.1(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.3.3(transitive)
+ Addedrequest@2.78.0(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsntp@1.0.9(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstringstream@0.0.6(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtough-cookie@2.3.4(transitive)
+ Addedtunnel-agent@0.4.3(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduuid@2.0.3(transitive)
+ Addedverror@1.10.0(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedasn1@0.1.11(transitive)
- Removedassert-plus@0.1.5(transitive)
- Removedasync@0.9.2(transitive)
- Removedaws-sign2@0.5.0(transitive)
- Removedboom@0.4.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removedcryptiles@0.2.2(transitive)
- Removedctype@0.5.3(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedforever-agent@0.5.2(transitive)
- Removedform-data@0.1.4(transitive)
- Removedhawk@1.0.0(transitive)
- Removedhoek@0.9.1(transitive)
- Removedhttp-signature@0.10.1(transitive)
- Removedmime@1.2.11(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@0.6.6(transitive)
- Removedrequest@2.34.0(transitive)
- Removedsntp@0.2.4(transitive)
- Removedtldts@6.1.71(transitive)
- Removedtldts-core@6.1.71(transitive)
- Removedtough-cookie@5.1.0(transitive)
- Removedtunnel-agent@0.3.0(transitive)
- Removeduuid@1.4.2(transitive)
Updatedrequest@~2.78.0
Updateduuid@~2.0.3