Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
This is a nodejs package for steam email auth.
It uses IMAP to fetch the latest emails and gives you the last key it could get.

This fork has been updated to support the new email format steam uses (URL verification instead of code).
The previous is depreciated.

## Installation
It is as easy as always:

```
npm install steam-email-auth
```
Install is to clone this fork, unless the main npm package gets updated.

A reminder you may need to allow gmail for 'insecure apps' and possibly login to the account on the same IP in a browser for it to work.

## Example Usage
```
var SteamEmailAuth = require('steam-email-auth');
var request = require('request');

var auth = new SteamEmailAuth({
user: 'user@gmail.com',
password: "gmailpass",
Expand All @@ -21,18 +25,22 @@ var auth = new SteamEmailAuth({
tls: true
});

auth.fetchLastAuthCode({}, function (key) {
console.log("Key: "+ key)
});
```

If you use the email for multiple accounts, you should prefer this call:

```
auth.fetchLastAuthCode({
username: "username here!"
}, function (key) {
console.log("Key: "+ key)
auth.fetchLastAuthCode({username: "steamusername"}, function (url) {
var options = {
url: url,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
}
};

function callback(error, response, body) {
if (error) {
console.log("There was an error requesting the URL: " + error.message);
} else {
console.log("URL requested successfully");
}
}
request(options, callback); //run request on URL
});
```

Expand All @@ -43,6 +51,5 @@ auth.fetchLastAuthCode({
Creates a new IMAP connection and returns the guard key it has found.
* `options` - an object representing the configuration. Can be {}.
* `username` (optional) - The username (login) whick key we are searching. Use this if you have multiple steam accounts on this email.
* `type` (optional) - "web", "computer" or nothing. To filter what type of auth you need (web is also mobile).
* `callback(key)` - a function, getting the guard key as first argument.
* `key` - The guard key. NULL if none has been found.
* `callback(url)` - a function, getting the url as first argument.
* `url` - The url. NULL if none has been found.
30 changes: 18 additions & 12 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var SteamEmailAuth = require("./index.js");
var SteamEmailAuth = require('steam-email-auth');
var request = require('request');

var auth = new SteamEmailAuth({
user: 'user@gmail.com',
Expand All @@ -8,15 +9,20 @@ var auth = new SteamEmailAuth({
tls: true
});

auth.fetchLastAuthCode({
username: "username"
}, function (key) {
console.log("Key: "+ key)
auth.fetchLastAuthCode({username: "steamusername"}, function (url) {
var options = {
url: url,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
}
};

function callback(error, response, body) {
if (error) {
console.log("There was an error requesting the URL: " + error.message);
} else {
console.log("URL requested successfully");
}
}
request(options, callback); //run request on URL
});







37 changes: 8 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

require('util').inherits(SteamEmailAuth, require('events').EventEmitter);
var Imap = require("imap");
function SteamEmailAuth(options) {
Expand All @@ -7,19 +6,12 @@ function SteamEmailAuth(options) {

this.options.port = this.options.port || 993;
this.options.tls = this.options.tls || true;


}

module.exports = SteamEmailAuth;

// type: "web", "computer", "" or nothing
SteamEmailAuth.prototype.fetchLastAuthCode = function (options, callback) {

var type = options.type || ""
var username = options.username || ""


var _this = this;
var imap = new Imap(this.options);

Expand All @@ -30,13 +22,12 @@ SteamEmailAuth.prototype.fetchLastAuthCode = function (options, callback) {
var date = new Date();
date.setTime(date.getTime() - 1000 * 60 * 60 * 24);


imap.once('ready', function () {
imap.openBox('INBOX', true, function (err, box) {
imap.search( [
imap.search( [
//"UNSEEN", // Maybe this will help speeding up? But maybe we miss some mail :s
["FROM", "noreply@steampowered.com"],
["SUBJECT", "Access from new" + type],
["SUBJECT", "Your Steam account: Email address verification"],
["BODY","Dear "+ username],
["SENTSINCE", date]
], function (err, results) {
Expand All @@ -51,40 +42,28 @@ SteamEmailAuth.prototype.fetchLastAuthCode = function (options, callback) {
bodies: 'TEXT' ,
markSeen: false
});
var _sent = false;
f.on('message', function (msg, seqno) {
if (_sent)
return null;
msg.on('body', function (stream, info) {
var data = "";
stream.on('data', function (chunk) {
data += chunk;
});

stream.on('end', function () {
var pattern = /\<span style="font-size: 24px; color: #66c0f4; font-family: Arial, Helvetica, sans-serif; font-weight: bold;"\>([0-9A-Z]{5})\<\/span\>/;
var pattern2 = /\n([0-9A-Z]{5})\r\n/
var match = data.match(pattern2) || data.match(pattern);

if (match && callback) {
callback(match[1]);
_sent = true;
}
stream.on('end', function () { //major change here... uses string manipulation to isolate the URL.
var match = data.split('<p><a style="color: #c6d4df;" href="').pop();
var match = match.split('">Click here to verify your email address.</a></p>')[0]
if (callback)
callback(match);
});
});
});

f.once('error', function (err) {
console.log('IMAP Fetch error: ' + err);

if (!_sent)
return callback();
});
f.once('end', function () {
imap.closeBox(function () {
imap.end();
if (!_sent)
return callback();
imap.end();
});
});
});
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "steam-email-auth",
"version": "0.1.0",
"version": "0.1.1",
"description": "steam-email-auth",
"main": "index.js",
"author": "Mijago <coding.mijago+nodejs@gmail.com>",
"author": "jfx <notemail@jfx.space>",
"dependencies": {
"imap": "0.8.16"
"imap": "^0.8.16"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Mijago/node-steam-email-auth.git"
"url": "git+https://github.com/itsjfx/node-steam-email-auth.git"
},
"keywords": [
"steam",
Expand All @@ -21,7 +21,7 @@
],
"license": "ISC",
"bugs": {
"url": "https://github.com/Mijago/node-steam-email-auth/issues"
"url": "https://github.com/itsjfx/node-steam-email-auth/issues"
},
"homepage": "https://github.com/Mijago/node-steam-email-auth#readme"
"homepage": "https://github.com/itsjfx/node-steam-email-auth#readme"
}